c++: Add test for c++/95143
authorMarek Polacek <polacek@redhat.com>
Mon, 18 May 2020 17:50:39 +0000 (13:50 -0400)
committerMarek Polacek <polacek@redhat.com>
Mon, 18 May 2020 17:50:39 +0000 (13:50 -0400)
Already fixed by r10-8124-gceae6a13366d9646e172fc943fe8e221b70f0920.

PR c++/95143
* g++.dg/cpp0x/sfinae66.C: New test.

gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/sfinae66.C [new file with mode: 0644]

index 320095c49ae09abbb01672a8a07a7b4e22250117..008e4483169d459818e1b7743510b34914701fb4 100644 (file)
@@ -1,3 +1,8 @@
+2020-05-18  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/95143
+       * g++.dg/cpp0x/sfinae66.C: New test.
+
 2020-05-18  Uroš Bizjak  <ubizjak@gmail.com>
 
        PR target/95169
diff --git a/gcc/testsuite/g++.dg/cpp0x/sfinae66.C b/gcc/testsuite/g++.dg/cpp0x/sfinae66.C
new file mode 100644 (file)
index 0000000..49067cd
--- /dev/null
@@ -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, "");
+}