From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 087853858C2D for ; Tue, 27 Sep 2022 12:18:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 087853858C2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664281121; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=dU6T6Erjluu4ALMI/Mo+yCwjy3rk6kv8necXgMNPT0k=; b=ecOX0W403yrQTARPy7gkViiEaZnopXgPR+dbRJGYvpMIwa+Q0/BVyAGq5e2gjzZ3hw60Fn mRcvMnALgQ/VGcsO2KuDcm5hOTSjciJqrWP3peX0AK/pmPkjnyp3VnQXBjhw6K+94VINAv KKyhaI76TppY9yxoSBotVyPH79472ek= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-575-Ci6IoCAGPb6afiWkHOjGDA-1; Tue, 27 Sep 2022 08:18:39 -0400 X-MC-Unique: Ci6IoCAGPb6afiWkHOjGDA-1 Received: by mail-qk1-f200.google.com with SMTP id i7-20020a05620a404700b006ced0d02b68so7185831qko.10 for ; Tue, 27 Sep 2022 05:18:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date; bh=dU6T6Erjluu4ALMI/Mo+yCwjy3rk6kv8necXgMNPT0k=; b=JTjGwqm3uAoDSYyo1CaRL3OdxAwTR3+e0EErcArb3JNxghxnWtmsMngjl2Vl01aieQ hI7Ict7LCf9wAIIBLAzlA0nCA9vnhpBzq5t8vV7uhXto82sni25ih7tVwylSCmcj9Wch VvXzFTa0BhRSngNrE43o3PlLqVNYfx8sJzSUN5YuD4oCopNlVqPgEguMd2UiMfzeKJwR sHvk8Q+gkTZcSfNQQRQZL2+5s9G9BY91R1iSpvIQFyks1gWzL7OTXczh8F7TOc8In9Pe dA41JzycRLQZXrMYveqp7lQ5nuhk3iZPrWIdZZ513z7w5/OaIfVT24ehiJNX0l2bwpWN 8Dpg== X-Gm-Message-State: ACrzQf3zBV/QmCXqXblyAnq+ofedfHIvFJfunGDdErmYfcApRADWleTX 9amsQlk6tV4jTssbq/JEe5zOPgCQ1l+VAxsS4IuYXqUEuIzc+YcjAQWAj261I7cZ22yez3VcvaH 6yw7L5JWsOM1zmeY= X-Received: by 2002:a05:6214:27e2:b0:4ac:97ba:57b5 with SMTP id jt2-20020a05621427e200b004ac97ba57b5mr21061185qvb.130.1664281119266; Tue, 27 Sep 2022 05:18:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5mC2o+Hz50haC88OmkDib4m4EvRjfTfGqbdGqBej2Bh4fEQS410TP9Pe8oWnBY2wd6ZpyT2A== X-Received: by 2002:a05:6214:27e2:b0:4ac:97ba:57b5 with SMTP id jt2-20020a05621427e200b004ac97ba57b5mr21061164qvb.130.1664281118986; Tue, 27 Sep 2022 05:18:38 -0700 (PDT) Received: from redhat.com (2603-7000-9500-2e39-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:2e39::1db4]) by smtp.gmail.com with ESMTPSA id a10-20020a05622a02ca00b0035d4f68232esm512388qtx.3.2022.09.27.05.18.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 05:18:38 -0700 (PDT) Date: Tue, 27 Sep 2022 08:18:36 -0400 From: Marek Polacek To: Jonathan Wakely Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org, Jason Merrill Subject: Re: [PATCH] c++: Make __is_{,nothrow_}convertible SFINAE on access [PR107049] Message-ID: References: <20220927103510.2321453-1-jwakely@redhat.com> MIME-Version: 1.0 In-Reply-To: <20220927103510.2321453-1-jwakely@redhat.com> User-Agent: Mutt/2.2.7 (2022-08-07) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, Sep 27, 2022 at 11:35:10AM +0100, Jonathan Wakely wrote: > Tested powerpc64le-linux. OK for trunk? > > -- >8 -- > > The is_convertible built-ins should return false if the conversion fails > an access check, not report an error. Ah, so we do need that sentinel after all. Patch looks good, thanks. > 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. > --- > gcc/cp/method.cc | 1 + > gcc/testsuite/g++.dg/ext/is_convertible4.C | 33 +++++++++++++++++++ > .../g++.dg/ext/is_nothrow_convertible4.C | 33 +++++++++++++++++++ > .../is_convertible/requirements/access.cc | 18 ++++++++++ > 4 files changed, 85 insertions(+) > create mode 100644 gcc/testsuite/g++.dg/ext/is_convertible4.C > create mode 100644 gcc/testsuite/g++.dg/ext/is_nothrow_convertible4.C > create mode 100644 libstdc++-v3/testsuite/20_util/is_convertible/requirements/access.cc > > 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, "" ); > -- > 2.37.3 > Marek