summaryrefslogtreecommitdiffstats
path: root/test/SemaCXX/int-ptr-cast-SFINAE.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/SemaCXX/int-ptr-cast-SFINAE.cpp')
-rw-r--r--test/SemaCXX/int-ptr-cast-SFINAE.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/SemaCXX/int-ptr-cast-SFINAE.cpp b/test/SemaCXX/int-ptr-cast-SFINAE.cpp
new file mode 100644
index 0000000000..5782a6dbae
--- /dev/null
+++ b/test/SemaCXX/int-ptr-cast-SFINAE.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++14
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++17
+
+void foo(int* a, int *b) {
+ a -= b; // expected-warning {{incompatible integer to pointer conversion assigning to 'int *' from}}
+}
+
+template<typename T> T declval();
+struct true_type { static const bool value = true; };
+struct false_type { static const bool value = false; };
+template<bool, typename T, typename U> struct select { using type = T; };
+template<typename T, typename U> struct select<false, T, U> { using type = U; };
+
+
+template<typename T>
+typename select<(sizeof(declval<T>() -= declval<T>(), 1) != 1), true_type, false_type>::type test(...);
+template<typename T> false_type test(...);
+
+template<typename T>
+static const auto has_minus_assign = decltype(test<T>())::value;
+
+static_assert(has_minus_assign<int*>, "failed"); // expected-error {{static_assert failed due to requirement 'has_minus_assign<int *>' "failed"}}