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 ESMTP id 33CB0385802B for ; Tue, 28 Sep 2021 19:51:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 33CB0385802B Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-504-aADMqNl8P8mH7qMu_WfPrA-1; Tue, 28 Sep 2021 15:51:28 -0400 X-MC-Unique: aADMqNl8P8mH7qMu_WfPrA-1 Received: by mail-qk1-f199.google.com with SMTP id j6-20020a05620a288600b0045e5d85ca17so5395812qkp.16 for ; Tue, 28 Sep 2021 12:51:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=epM7+Zn42LqW9ZDv7u0EhIMzn+IgvH6Gj8Tfuksd7X4=; b=w4VANN8VTrEmPMERtNf98N7plamd4SWAcujBmhDEkBSButwINbYBaBaZL7MRjIuhqy qVn94myrpv+hQV0vFBTm8JISndsmRm/L3iww7AkpI5/w+ZcC+jn6S3RwYYwMGnZivc+g bSUc3j93V+tmp0uYH0Ow+B++vxBTodRkBhcC4eBi8EWm8jEf+r+6dJwkBMVnYJFSgpKP DuLm8YMiJwzRlizNIdBCm9HwuqxYYNcaFubM3nWVYMhGDaMgRkBQ1baE/YBtQr0d67+o A5Ozyfffws4XmakV9l4r/7BWduZdC7i5Uh6xvdflMtZsFb6QTRVYlM4ME5XeTMHyc473 pWtQ== X-Gm-Message-State: AOAM532Hx2oBGEmRitYkct6LcCwuAYxcv2vmysm4xPF/NTFDPd+R7xLU jGMnXyHvUOE6HQNwTWKAG0r1VXnKiFVVe9B0NhEdFCzc8MaukIk3x+CyDZ5dKK7EPw9d5T+I+oy r65ZTZFwv4dzZ0pPyKg== X-Received: by 2002:a05:6214:5a1:: with SMTP id by1mr1635117qvb.42.1632858687128; Tue, 28 Sep 2021 12:51:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpPuBfr6JDGoOO5zS2B6CeGbfp2VQMaFo2plwCKA23qFwV7vL2C6ppwYmTQvtgfvS2f8j1PA== X-Received: by 2002:a05:6214:5a1:: with SMTP id by1mr1635087qvb.42.1632858686753; Tue, 28 Sep 2021 12:51:26 -0700 (PDT) Received: from [192.168.1.149] (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 q184sm82473qkd.35.2021.09.28.12.51.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 Sep 2021 12:51:26 -0700 (PDT) Message-ID: <41fa824d-59ff-07d1-50f5-2aacd88abf7e@redhat.com> Date: Tue, 28 Sep 2021 15:51:25 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.1 Subject: Re: [PATCH] c++: Suppress error when cv-qualified reference is introduced by typedef [PR101783] To: nick huang , Gcc-patches References: 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=-14.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Sep 2021 19:51:34 -0000 On 9/26/21 21:31, nick huang via Gcc-patches wrote: > Hi Jason, > > 1. Thank you very much for your detailed comments for my patch and I really appreciate it! Here is my revised patch: > > The root cause of this bug is that it considers reference with > cv-qualifiers as an error by generating value for variable "bad_quals". > However, this is not correct for case of typedef. Here I quote spec: > "Cv-qualified references are ill-formed except when the cv-qualifiers > are introduced through the use of a typedef-name ([dcl.typedef], > [temp.param]) or decltype-specifier ([dcl.type.decltype]), > in which case the cv-qualifiers are ignored." > > 2021-09-25 qingzhe huang > > gcc/cp/ > PR c++/101783 > * tree.c (cp_build_qualified_type_real): git gcc-verify still rejects this line with ERR: missing description of a change: " * tree.c (cp_build_qualified_type_real):" You may need to run contrib/gcc-git-customization.sh to get the git gcc-verify command. > gcc/testsuite/ > PR c++/101783 > * g++.dg/parse/pr101783.C: New test. > -------------- next part -------------- Please drop this line, it breaks git gcc-verify when I apply the patch with git am. The patch should start immediately after the ChangeLog entries. > diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c > index 8840932dba2..d5c8daeb340 100644 > --- a/gcc/cp/tree.c > +++ b/gcc/cp/tree.c > @@ -1356,11 +1356,18 @@ cp_build_qualified_type_real (tree type, > /* A reference or method type shall not be cv-qualified. > [dcl.ref], [dcl.fct]. This used to be an error, but as of DR 295 > (in CD1) we always ignore extra cv-quals on functions. */ > + > + /* Cv-qualified references are ill-formed except when the cv-qualifiers In my previous reply I meant please add "[dcl.ref]/1" at the beginning of this comment. > + are introduced through the use of a typedef-name ([dcl.typedef], > + [temp.param]) or decltype-specifier ([dcl.type.decltype]), > + in which case the cv-qualifiers are ignored. > + */ > if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE) > && (TYPE_REF_P (type) > || FUNC_OR_METHOD_TYPE_P (type))) > { > - if (TYPE_REF_P (type)) > + if (TYPE_REF_P (type) > + && (!typedef_variant_p (type) || FUNC_OR_METHOD_TYPE_P (type))) > bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE); > type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE); > } > diff --git a/gcc/testsuite/g++.dg/parse/pr101783.C b/gcc/testsuite/g++.dg/parse/pr101783.C > new file mode 100644 > index 00000000000..4e0a435dd0b > --- /dev/null > +++ b/gcc/testsuite/g++.dg/parse/pr101783.C > @@ -0,0 +1,5 @@ > +template struct A{ > + typedef T& Type; > +}; > +template void f(const typename A::Type){} > +template <> void f(const typename A::Type){} > > > > 2. >> In Jonathan's earlier reply he asked how you tested the patch; this >> message still doesn't say anything about that. > I communicated with Mr. Jonathan in private email, worrying my naive question might pollute the public maillist. The following is major part of this communication and I attached original part in attachment. > >>>> How has this patch been tested? Have you bootstrapped the compiler and >>>> run the full testsuite? > Here is how I am doing: > a) build original 10.2.0 from scratch and make check to get both "testsuite/gcc/gcc.sum" > and "testsuite/g++/g++.sum". > b) apply my patch and build from scratch and make check to get both two files above. > c) compare two run's *.sum files to see if there is any difference. > > (Later I realized there is tool "contrib/compare_tests" is a good help of doing so.) > > 3. >> What is the legal status of your contributions? > I thought small patch didn't require assignment. However, I just sent email to assign@gnu.org to request assignment. > Alternatively, I am not sure if adding this "signoff" tag in submission will help? > Signed-off-by: qingzhe huang > > > Thank you again! > > >> On 8/28/21 07:54, nick huang via Gcc-patches wrote: >>> Reference with cv-qualifiers should be ignored instead of causing an error >>> because standard accepts cv-qualified references introduced by typedef which >>> is ignored. >>> Therefore, the fix prevents GCC from reporting error by not setting variable >>> "bad_quals" in case the reference is introduced by typedef. Still the >>> cv-qualifier is silently ignored. >>> Here I quote spec (https://timsong-cpp.github.io/cppwp/dcl.ref#1): >>> "Cv-qualified references are ill-formed except when the cv-qualifiers >>> are introduced through the use of a typedef-name ([dcl.typedef], >>> [temp.param]) or decltype-specifier ([dcl.type.decltype]), >>> in which case the cv-qualifiers are ignored." >>> >>> PR c++/101783 >>> >>> gcc/cp/ChangeLog: >>> >>> 2021-08-27 qingzhe huang >>> >>> * tree.c (cp_build_qualified_type_real): >> >> The git commit verifier rejects this commit message with >> >> Checking 1fa0fbcdd15adf936ab4fae584f841beb35da1bb: FAILED ERR: missing >> description of a change: >> " * tree.c (cp_build_qualified_type_real):" >> >> (your initial patch had a description here, you just need to copy it over) >> >> ERR: PR 101783 in subject but not in changelog: >> "c++: Suppress error when cv-qualified reference is introduced by >> typedef [PR101783]" >> >> (the PR number needs to have a Tab before it) >> >> In Jonathan's earlier reply he asked how you tested the patch; this >> message still doesn't say anything about that. >> >> https://gcc.gnu.org/contribute.html#testing >> >> What is the legal status of your contributions? >> >> https://gcc.gnu.org/contribute.html#legal >> >> Existing code tries to handle this with the tf_ignore_bad_quals, but the >> unnecessary use of typename gets past the code that tries to set the >> flag. But your approach is nice and straightforward, so let's go ahead >> with it. >> >>> gcc/testsuite/ChangeLog: >>> >>> 2021-08-27 qingzhe huang >>> >>> * g++.dg/parse/pr101783.C: New test. >>> >>> diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c >>> index 8840932dba2..7aa4318a574 100644 >>> --- a/gcc/cp/tree.c >>> +++ b/gcc/cp/tree.c >>> @@ -1356,12 +1356,22 @@ cp_build_qualified_type_real (tree type, >>> /* A reference or method type shall not be cv-qualified. >>> [dcl.ref], [dcl.fct]. This used to be an error, but as of DR 295 >>> (in CD1) we always ignore extra cv-quals on functions. */ >>> + >>> + /* PR 101783 >> >> Let's cite where this comes from in the standard ([dcl.ref]/1), and not >> the PR number. >> >>> + Cv-qualified references are ill-formed except when the cv-qualifiers >>> + are introduced through the use of a typedef-name ([dcl.typedef], >>> + [temp.param]) or decltype-specifier ([dcl.type.decltype]), >>> + in which case the cv-qualifiers are ignored. >>> + */ >>> if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE) >>> && (TYPE_REF_P (type) >>> || FUNC_OR_METHOD_TYPE_P (type))) >>> { >>> - if (TYPE_REF_P (type)) >>> + // do NOT set bad_quals when non-method reference is introduced by typedef. >>> + if (TYPE_REF_P (type) >>> + && (!typedef_variant_p (type) || FUNC_OR_METHOD_TYPE_P (type))) >>> bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE); >>> + // non-method reference introduced by typedef is also dropped silently >> >> These two // comments seem redundant with the quote from the standard >> above, let's drop them. >> >>> type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE); >>> } >>> >>> diff --git a/gcc/testsuite/g++.dg/parse/pr101783.C b/gcc/testsuite/g++.dg/parse/pr101783.C >>> new file mode 100644 >>> index 00000000000..4e0a435dd0b >>> --- /dev/null >>> +++ b/gcc/testsuite/g++.dg/parse/pr101783.C >>> @@ -0,0 +1,5 @@ >>> +template struct A{ >>> + typedef T& Type; >>> +}; >>> +template void f(const typename A::Type){} >>> +template <> void f(const typename A::Type){} >>> >>>