r351495 - Make integral-o-pointer conversions in SFINAE illegal.

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 17 15:11:15 PST 2019


Author: erichkeane
Date: Thu Jan 17 15:11:15 2019
New Revision: 351495

URL: http://llvm.org/viewvc/llvm-project?rev=351495&view=rev
Log:
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

Added:
    cfe/trunk/test/SemaCXX/int-ptr-cast-SFINAE.cpp   (with props)
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=351495&r1=351494&r2=351495&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jan 17 15:11:15 2019
@@ -6817,7 +6817,7 @@ def ext_typecheck_convert_int_pointer :
   "; 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 $|"

Added: cfe/trunk/test/SemaCXX/int-ptr-cast-SFINAE.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/int-ptr-cast-SFINAE.cpp?rev=351495&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/int-ptr-cast-SFINAE.cpp (added)
+++ cfe/trunk/test/SemaCXX/int-ptr-cast-SFINAE.cpp Thu Jan 17 15:11:15 2019
@@ -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"}}

Propchange: cfe/trunk/test/SemaCXX/int-ptr-cast-SFINAE.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/SemaCXX/int-ptr-cast-SFINAE.cpp
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Rev URL"

Propchange: cfe/trunk/test/SemaCXX/int-ptr-cast-SFINAE.cpp
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the cfe-commits mailing list