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.133.124]) by sourceware.org (Postfix) with ESMTPS id 2D1C13858438 for ; Tue, 27 Sep 2022 12:18:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2D1C13858438 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=1664281122; 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=X1UvRQ42UCCI6cvxn9Ke3R/oof2EHTkIJcUQuO6TAzcypVpqIzrrEb3/StN8k5fC9TIjEx vhfzYoBwZj3phh6gxAub11NIrr7sD9HmqQYC8M34z6pBRp6nicDCzGLGAJJYL0xBo8l+Sf yOvY3iw9/pXMs9FeKdcn3LZz1H/WIP8= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-620-XFA0ZXR5NiSR2yFZn1YRrg-1; Tue, 27 Sep 2022 08:18:39 -0400 X-MC-Unique: XFA0ZXR5NiSR2yFZn1YRrg-1 Received: by mail-qv1-f70.google.com with SMTP id jo23-20020a056214501700b004af8b197efaso1071342qvb.1 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=HF7eekc1UFw8oNrJDBMn3t9MjaCdJ7MC3A254IRvixLJdtdqnN5CEQR++NpCCOnrb+ +ASTJgc89upRw0Fmg5m277fgrOjQgjRoC7p63tlmhuQW69hpaJrj3al36aKLTzatCwQh lQcGkWibfh+IH+RqUZTUavKPSPrW/8r+GRM+tnaJulgLIIcWSHXnA464Ca6oBrspd7Nt 561/cGSwBVEKsJUq8feLt2d/DiplG4/80icRobtSZtOcqB4aXtAVYNrZ1/hznHXwCi7t CJStb6wm1XDt7lBooJmqkcq+5tL2vanqrA1OgvN5oHaYcDoTfhgHbTQuSufx+KSfYXYX YFIA== X-Gm-Message-State: ACrzQf171kVobVvsID7jgHkSHPchDxLF+boI6MIbCfVS4FmvyUi7mO8K EiJQrihG8MjE9lodBpEEpE52dhGIvghPG0hOXR+KpFvcCDKCwQQT1J3uPyDqJzKZ+dQeUbvJJGE 6WKSZ0wGkTo0vyPbk6A== X-Received: by 2002:a05:6214:27e2:b0:4ac:97ba:57b5 with SMTP id jt2-20020a05621427e200b004ac97ba57b5mr21061184qvb.130.1664281119265; 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.2 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_NONE,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=unavailable 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