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 91C6E3858C62 for ; Mon, 26 Sep 2022 16:41:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 91C6E3858C62 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=1664210467; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/l9No64isE9DcjWPAdNx60yuegGBYoYddAhklOr0NCs=; b=RuwBV66ivCe7QDZxDutMSuC/9tP5hS7/0XG2nmflCkL1F5ac5jogYBG7FVKFUBXeGy+Pxl TSlQZY6pJRaKUPtDfU+wdHeokhAtFV2k1ycqP14g8HoFg79UKqbqTNJt40uPJpLYUK9QB6 +7Sxe1xJ6cXUd7Rcf8K7dWZqPHiJZ+8= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-222-T3bDzR6IMY6qnxyE6Y9tIQ-1; Mon, 26 Sep 2022 12:41:06 -0400 X-MC-Unique: T3bDzR6IMY6qnxyE6Y9tIQ-1 Received: by mail-qv1-f71.google.com with SMTP id f10-20020ad443ea000000b004aca9fabe98so4113708qvu.18 for ; Mon, 26 Sep 2022 09:41:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=/l9No64isE9DcjWPAdNx60yuegGBYoYddAhklOr0NCs=; b=CyJA3Up8hVuZNfLZVusulOQVpRwA64u79YnMTfTXtGSCL4M+/IihfbBCDcHEA9cMF8 AzV7uAhTi9RwcuUzwzSWCE0pOLuhgNV5IyX7Q72Od1pnPuJ85GHN3I4kw+nyftLcaPOz SGyVn9B00pJfyIwO9zhuhjtOItjj1G9EbJkDSwvZp37XS64ulEU35lk8BmaLT9GZUutp 9s5aJzcj501Oqux7NMeyax52yNehqauznBAvRBtbh5GyjVj7SefGTgoSrKjAp10NYsO7 JbiaPFbc68dVtSmdXSD1OP0fMDoV+6Of+4BmfMpoClCsUP2q92hZseAabp7yRs/32i+Q 0Udg== X-Gm-Message-State: ACrzQf2Nboxq2l4i0I3DdS10rarUh1vUh0LpEWnWSJ0BBmhunC7ZugMa N3zRI/A0Fd6AtqsXLBzfCegxFROkkakwXYUHABzQYtTSRL4QElD7iryujTPQvs00B0apDdcTfbb FnuvIVoVNVd6UvGN3dw== X-Received: by 2002:a05:620a:2954:b0:6cf:9084:f7ab with SMTP id n20-20020a05620a295400b006cf9084f7abmr6409685qkp.355.1664210465751; Mon, 26 Sep 2022 09:41:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM71q9R5Ld3yM+n+Od/mfPATHn9+a/BoHuJvIKa6kA//N9fX9y5Hlii/Z+F14L/Xt+uH0qLD7A== X-Received: by 2002:a05:620a:2954:b0:6cf:9084:f7ab with SMTP id n20-20020a05620a295400b006cf9084f7abmr6409671qkp.355.1664210465431; Mon, 26 Sep 2022 09:41:05 -0700 (PDT) Received: from [192.168.1.101] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id t11-20020ac865cb000000b0035bbc29b3c9sm10863274qto.60.2022.09.26.09.41.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 26 Sep 2022 09:41:04 -0700 (PDT) Message-ID: Date: Mon, 26 Sep 2022 12:41:04 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.13.1 Subject: Re: [PATCH v2] c++: Instantiate less when evaluating __is_convertible To: Marek Polacek , Patrick Palka Cc: GCC Patches , Jonathan Wakely References: <20220926152258.20921-1-polacek@redhat.com> <22a3074f-0180-5ab6-5a9d-c27f8db507c7@idea> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,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 9/26/22 12:25, Marek Polacek wrote: > On Mon, Sep 26, 2022 at 11:51:30AM -0400, Patrick Palka wrote: >> On Mon, 26 Sep 2022, Marek Polacek via Gcc-patches wrote: >> >>> Jon reported that evaluating __is_convertible in this test leads to >>> instantiating char_traits::eq, which is invalid (because we >>> are trying to call a member function on a char) and so we fail to >>> compile the test. __is_convertible doesn't and shouldn't need to >>> instantiate so much, so let's limit it with a cp_unevaluated guard. >>> >>> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? >>> >>> PR c++/106784 >>> >>> gcc/cp/ChangeLog: >>> >>> * method.cc (is_convertible): Use cp_unevaluated. >> >> I think is_nothrow_convertible would need cp_unevaluated too (or maybe we >> should define is_nothrow_convertible in terms of is_convertible). > > /facepalm, that's what I get by not using a single implementation for both! > >> And the testcase can probably be minimized to something like: >> >> struct A; >> struct B { template B(const T&) noexcept { T::nonexistent; } }; >> >> static_assert(__is_convertible(const A&, B)); >> static_assert(__is_nothrow_convertible(const A&, B)); > > Adjusted, thanks. > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? OK. > -- >8 -- > Jon reported that evaluating __is_convertible in a test led to > instantiating something ill-formed and so we failed to compile the test. > __is_convertible doesn't and shouldn't need to instantiate so much, so > let's limit it with a cp_unevaluated guard. Use a helper function to > implement both built-ins. > > PR c++/106784 > > gcc/cp/ChangeLog: > > * method.cc (is_convertible_helper): New. > (is_convertible): Use it. > (is_nothrow_convertible): Likewise. > > gcc/testsuite/ChangeLog: > > * g++.dg/ext/is_convertible3.C: New test. > * g++.dg/ext/is_nothrow_convertible3.C: New test. > --- > gcc/cp/method.cc | 23 ++++++++++++------- > gcc/testsuite/g++.dg/ext/is_convertible3.C | 9 ++++++++ > .../g++.dg/ext/is_nothrow_convertible3.C | 9 ++++++++ > 3 files changed, 33 insertions(+), 8 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/ext/is_convertible3.C > create mode 100644 gcc/testsuite/g++.dg/ext/is_nothrow_convertible3.C > > diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc > index c35a59fe56c..9f917f13134 100644 > --- a/gcc/cp/method.cc > +++ b/gcc/cp/method.cc > @@ -2236,6 +2236,19 @@ ref_xes_from_temporary (tree to, tree from, bool direct_init_p) > return ref_conv_binds_directly (to, val, direct_init_p).is_false (); > } > > +/* Worker for is_{,nothrow_}convertible. Attempt to perform an implicit > + conversion from FROM to TO and return the result. */ > + > +static tree > +is_convertible_helper (tree from, tree to) > +{ > + if (VOID_TYPE_P (from) && VOID_TYPE_P (to)) > + return integer_one_node; > + cp_unevaluated u; > + tree expr = build_stub_object (from); > + return perform_implicit_conversion (to, expr, tf_none); > +} > + > /* Return true if FROM can be converted to TO using implicit conversions, > or both FROM and TO are possibly cv-qualified void. NB: This doesn't > implement the "Access checks are performed as if from a context unrelated > @@ -2244,10 +2257,7 @@ ref_xes_from_temporary (tree to, tree from, bool direct_init_p) > bool > is_convertible (tree from, tree to) > { > - if (VOID_TYPE_P (from) && VOID_TYPE_P (to)) > - return true; > - tree expr = build_stub_object (from); > - expr = perform_implicit_conversion (to, expr, tf_none); > + tree expr = is_convertible_helper (from, to); > if (expr == error_mark_node) > return false; > return !!expr; > @@ -2258,10 +2268,7 @@ is_convertible (tree from, tree to) > bool > is_nothrow_convertible (tree from, tree to) > { > - if (VOID_TYPE_P (from) && VOID_TYPE_P (to)) > - return true; > - tree expr = build_stub_object (from); > - expr = perform_implicit_conversion (to, expr, tf_none); > + tree expr = is_convertible_helper (from, to); > if (expr == NULL_TREE || expr == error_mark_node) > return false; > return expr_noexcept_p (expr, tf_none); > diff --git a/gcc/testsuite/g++.dg/ext/is_convertible3.C b/gcc/testsuite/g++.dg/ext/is_convertible3.C > new file mode 100644 > index 00000000000..7a986d075c2 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/ext/is_convertible3.C > @@ -0,0 +1,9 @@ > +// PR c++/106784 > +// { dg-do compile { target c++11 } } > +// Make sure we don't reject this at runtime by trying to instantiate > +// something that would be ill-formed. > + > +struct A; > +struct B { template B(const T&) noexcept { T::nonexistent; } }; > + > +static_assert(__is_convertible(const A&, B), ""); > diff --git a/gcc/testsuite/g++.dg/ext/is_nothrow_convertible3.C b/gcc/testsuite/g++.dg/ext/is_nothrow_convertible3.C > new file mode 100644 > index 00000000000..05b1e1d9ad9 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/ext/is_nothrow_convertible3.C > @@ -0,0 +1,9 @@ > +// PR c++/106784 > +// { dg-do compile { target c++11 } } > +// Make sure we don't reject this at runtime by trying to instantiate > +// something that would be ill-formed. > + > +struct A; > +struct B { template B(const T&) noexcept { T::nonexistent; } }; > + > +static_assert(__is_nothrow_convertible(const A&, B), ""); > > base-commit: 099a66498bf7a40764002793eba66c881a251b76