diff options
-rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 | ||||
-rw-r--r-- | clang/test/SemaCXX/int-ptr-cast-SFINAE.cpp | 22 |
2 files changed, 23 insertions, 1 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index a1029a22eb4..05e2d2dec2d 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -6817,7 +6817,7 @@ def ext_typecheck_convert_int_pointer : ExtWarn< "; take the address with &|" "; remove *|" "; remove &}3">, - InGroup<IntConversion>; + InGroup<IntConversion>, SFINAEFailure; def ext_typecheck_convert_pointer_void_func : Extension< "%select{%diff{assigning to $ from $|assigning to different types}0,1" "|%diff{passing $ to parameter of type $|" diff --git a/clang/test/SemaCXX/int-ptr-cast-SFINAE.cpp b/clang/test/SemaCXX/int-ptr-cast-SFINAE.cpp new file mode 100644 index 00000000000..1366eb4c371 --- /dev/null +++ b/clang/test/SemaCXX/int-ptr-cast-SFINAE.cpp @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// 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 'long'}} +} + +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"}} |