From: Erich Keane Date: Thu, 17 Jan 2019 23:11:15 +0000 (+0000) Subject: Make integral-o-pointer conversions in SFINAE illegal. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0a4307de1174f61c465c94111f8376d3f5ed548e;p=clang Make integral-o-pointer conversions in SFINAE illegal. As reported in PR40362, allowing the conversion from an integral to a pointer type (despite being illegal in the C++ standard) will cause surprsing results when testing for certain behaviors in SFINAE. This patch converts the error to a SFINAE Error and adds a test to ensure that it is still a warning in non-SFINAE but an error in it. Change-Id: I1f475637fa4d83217ae37dc6b5dbf653e118fae4 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@351495 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index a1029a22eb..05e2d2dec2 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -6817,7 +6817,7 @@ def ext_typecheck_convert_int_pointer : ExtWarn< "; take the address with &|" "; remove *|" "; remove &}3">, - InGroup; + InGroup, 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/test/SemaCXX/int-ptr-cast-SFINAE.cpp b/test/SemaCXX/int-ptr-cast-SFINAE.cpp new file mode 100644 index 0000000000..1366eb4c37 --- /dev/null +++ b/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 T declval(); +struct true_type { static const bool value = true; }; +struct false_type { static const bool value = false; }; +template struct select { using type = T; }; +template struct select { using type = U; }; + + +template +typename select<(sizeof(declval() -= declval(), 1) != 1), true_type, false_type>::type test(...); +template false_type test(...); + +template +static const auto has_minus_assign = decltype(test())::value; + +static_assert(has_minus_assign, "failed"); // expected-error {{static_assert failed due to requirement 'has_minus_assign' "failed"}}