From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 97F3138582BF; Tue, 27 Sep 2022 13:00:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 97F3138582BF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664283639; bh=U00QsFc2Jv/6nM9ozELYztvFavGfXGerQiCSqdrcWzI=; h=From:To:Subject:Date:From; b=UFH5UznHF71Na9xVKS/FM/qyucZz2l1O4funKARgll6xcnrkK/vokdQO53K5PMKi3 EosBpOukwLGyeiQdBL3tdPd1OWi4VxXcDO/TmjqOiWNzjip1R8J1CoWpczcyOEisE2 I28ju9oLFCjqrL76/aAkiLOlcbVYKbIpRhhQArks= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-2898] c++: Make __is_{, nothrow_}convertible SFINAE on access [PR107049] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 614e5696d730a65998ff5b0373f905795a758dd6 X-Git-Newrev: 3f7eea4411e4b2d8a500d9272b2ed72f73bdd008 Message-Id: <20220927130039.97F3138582BF@sourceware.org> Date: Tue, 27 Sep 2022 13:00:39 +0000 (GMT) List-Id: https://gcc.gnu.org/g:3f7eea4411e4b2d8a500d9272b2ed72f73bdd008 commit r13-2898-g3f7eea4411e4b2d8a500d9272b2ed72f73bdd008 Author: Jonathan Wakely Date: Tue Sep 27 09:51:10 2022 +0100 c++: Make __is_{,nothrow_}convertible SFINAE on access [PR107049] The is_convertible built-ins should return false if the conversion fails an access check, not report an error. PR c++/107049 gcc/cp/ChangeLog: * method.cc (is_convertible_helper): Use access check sentinel. gcc/testsuite/ChangeLog: * g++.dg/ext/is_convertible4.C: New test. * g++.dg/ext/is_nothrow_convertible4.C: New test. libstdc++-v3/ChangeLog: * testsuite/20_util/is_convertible/requirements/access.cc: New test. Diff: --- gcc/cp/method.cc | 1 + gcc/testsuite/g++.dg/ext/is_convertible4.C | 33 ++++++++++++++++++++++ gcc/testsuite/g++.dg/ext/is_nothrow_convertible4.C | 33 ++++++++++++++++++++++ .../20_util/is_convertible/requirements/access.cc | 18 ++++++++++++ 4 files changed, 85 insertions(+) diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc index 9f917f13134..55af5c43c18 100644 --- a/gcc/cp/method.cc +++ b/gcc/cp/method.cc @@ -2246,6 +2246,7 @@ is_convertible_helper (tree from, tree to) return integer_one_node; cp_unevaluated u; tree expr = build_stub_object (from); + deferring_access_check_sentinel acs (dk_no_deferred); return perform_implicit_conversion (to, expr, tf_none); } diff --git a/gcc/testsuite/g++.dg/ext/is_convertible4.C b/gcc/testsuite/g++.dg/ext/is_convertible4.C new file mode 100644 index 00000000000..8a7724c5852 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_convertible4.C @@ -0,0 +1,33 @@ +// PR c++/107049 +// { dg-do compile { target c++11 } } +// Failed access check should be a substitution failure, not an error. + +template +struct bool_constant { static constexpr bool value = B; }; + +template +struct is_convertible +: public bool_constant<__is_convertible(From, To)> +{ }; + +#if __cpp_variable_templates +template +constexpr bool is_convertible_v = __is_convertible(From, To); +#endif + +class Private +{ + operator int() const + { + static_assert( not is_convertible::value, "" ); +#if __cpp_variable_templates + static_assert( not is_convertible_v, "" ); +#endif + return 0; + } +}; + +static_assert( not is_convertible::value, "" ); +#if __cpp_variable_templates +static_assert( not is_convertible_v, "" ); +#endif diff --git a/gcc/testsuite/g++.dg/ext/is_nothrow_convertible4.C b/gcc/testsuite/g++.dg/ext/is_nothrow_convertible4.C new file mode 100644 index 00000000000..f81b5944ca2 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_nothrow_convertible4.C @@ -0,0 +1,33 @@ +// PR c++/107049 +// { dg-do compile { target c++11 } } +// Failed access check should be a substitution failure, not an error. + +template +struct bool_constant { static constexpr bool value = B; }; + +template +struct is_nt_convertible +: public bool_constant<__is_nothrow_convertible(From, To)> +{ }; + +#if __cpp_variable_templates +template +constexpr bool is_nt_convertible_v = __is_nothrow_convertible(From, To); +#endif + +class Private +{ + operator int() const + { + static_assert( not is_nt_convertible::value, "" ); +#if __cpp_variable_templates + static_assert( not is_nt_convertible_v, "" ); +#endif + return 0; + } +}; + +static_assert( not is_nt_convertible::value, "" ); +#if __cpp_variable_templates +static_assert( not is_nt_convertible_v, "" ); +#endif diff --git a/libstdc++-v3/testsuite/20_util/is_convertible/requirements/access.cc b/libstdc++-v3/testsuite/20_util/is_convertible/requirements/access.cc new file mode 100644 index 00000000000..04a8c525961 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_convertible/requirements/access.cc @@ -0,0 +1,18 @@ +// { dg-do compile { target c++11 } } +// PR c++/107049 + +#include + +class Private +{ + operator int() const + { + static_assert( not std::is_convertible::value, "" ); +#if __cpp_lib_type_trait_variable_templates + static_assert( not std::is_convertible_v, "" ); +#endif + return 0; + } +}; + +static_assert( not std::is_convertible::value, "" );