diff gcc/testsuite/g++.dg/cpp0x/sfinae66.C @ 152:2b5abeee2509

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gcc/testsuite/g++.dg/cpp0x/sfinae66.C	Mon May 25 07:50:57 2020 +0900
@@ -0,0 +1,32 @@
+// PR c++/95143
+// { dg-do compile { target c++11 } }
+
+struct false_type {
+  static constexpr bool value = false;
+};
+
+struct true_type{
+  static constexpr bool value = true;
+};
+
+template<class T>
+T&& declval() noexcept;
+
+template<typename T, typename U, typename = U>
+struct is_static_castable : false_type
+{};
+template<typename T, typename U>
+struct is_static_castable<T, U, decltype(static_cast<U>(declval<T>()))> : true_type
+{};
+
+class Base { };
+struct A { };
+class B: public Base { };
+
+int main()
+{
+  constexpr auto canCast = is_static_castable<A, B>::value;
+  static_assert(!canCast, "");
+  constexpr auto canCast2 = is_static_castable<A, A>::value;
+  static_assert(canCast2, "");
+}