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

Keane, Erich via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 18 05:57:05 PST 2019


Thanks for the heads up!  Looking now.

-----Original Message-----
From: Peter Smith [mailto:peter.smith at linaro.org] 
Sent: Friday, January 18, 2019 2:33 AM
To: Keane, Erich <erich.keane at intel.com>
Cc: cfe-commits cfe <cfe-commits at lists.llvm.org>
Subject: Re: r351495 - Make integral-o-pointer conversions in SFINAE illegal.

Hello Erich,

The test added in this commit is failing on the Arm and Hexagon builders. I think that this is because the expected type "long" in the warning text is "int" on these platforms (possibly other 32-bit host platforms).

The raw output from an Arm machine is:
llvm-project/clang/test/SemaCXX/int-ptr-cast-SFINAE.cpp:5:5: warning:
incompatible integer to pointer conversion assigning to 'int *' from 'int'; take the address with &
  a -= b; // expected-warning {{incompatible integer to pointer conversion assigning to 'int *' from 'long'}}
    ^  ~
       &

Could you take a look and update the test?

Thanks in advance

Peter

On Thu, 17 Jan 2019 at 23:14, Erich Keane via cfe-commits <cfe-commits at lists.llvm.org> wrote:
>
> 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/Diag
> nosticSemaKinds.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-cas
> t-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
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


More information about the cfe-commits mailing list