From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11olkn2038.outbound.protection.outlook.com [40.92.19.38]) by sourceware.org (Postfix) with ESMTPS id 547DE3858C60 for ; Mon, 27 Sep 2021 01:31:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 547DE3858C60 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HZQpbtWGpYRnvvitcCFS7tlMufPFVeae8xVsc8h7NC/z4cz6li3ULPCLPTGHEa3GFDjrwm5fisjx/LZZFmV4T91Ug+V56c1hYmNAqBSTeXnUSRNT6EQKt+YdkuUBx6EuKzfE0ZxDK3fesT+aTQHQihdrRTsQx6jMtGALlmffUuTeG9AZmWqExpCc9SdwDhtQ7HZZGkxxqxj1O3VEhB83MNCdrK55JETMJs56waTXZho9ZUtMtcDF5lMrPMFfnd8MQOx++mMa3YXf3R6RhaqT/b7iSvx3JP/RKnveRo6nhqmnPFOt0qdvpz/S7Hi5DsJaF2/yFNAteyBGvlthrRyoBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Phv4K3dsx2WkT85bKfpdYtGNM/UjM9Ap7JZ2J9Wx8XE=; b=W0oGqHggqQDQ+mcjXySaVD1wb2nEVr+8TNd7kM952VLJHp1gDeoVOOhIh7mlMZ2ed44vXz3LcrQyibZXUVCDJyYFy4tXUpk8KMeKC+ts4gAlJSIGe0T59OqN8OK6j/iWDnSgaPVfTbTc442NZjKB5aJSFlXDUwp2PTRQs8M+kyofFYKbuvTxrBC3a8uXEUUgt8gsgvxFeQp7nPZ+6xB0v8WG4bylP77c8d0dN0H6CRMwt8g6rQWDEjaExx1EJulC8jO7YPQkWQTfH+yAgUrc9LSc/2kq4xjIAyp/16GjSiQy/lDS3EWW4FMn8+W10QX4IWddN02HSvffBFM8S5dqEQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from MWHPR0501MB3737.namprd05.prod.outlook.com (2603:10b6:301:7a::17) by MWHPR05MB3663.namprd05.prod.outlook.com (2603:10b6:301:47::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.10; Mon, 27 Sep 2021 01:31:21 +0000 Received: from MWHPR0501MB3737.namprd05.prod.outlook.com ([fe80::853a:8f60:a4f0:2ba0]) by MWHPR0501MB3737.namprd05.prod.outlook.com ([fe80::853a:8f60:a4f0:2ba0%4]) with mapi id 15.20.4566.012; Mon, 27 Sep 2021 01:31:21 +0000 From: nick huang To: David Edelsohn via Gcc-patches Subject: Re: [PATCH] c++: Suppress error when cv-qualified reference is introduced by typedef [PR101783] Thread-Topic: [PATCH] c++: Suppress error when cv-qualified reference is introduced by typedef [PR101783] Thread-Index: AQHXsrWZBJl9f3l5jUKsfMN27vIgLau3A78G Date: Mon, 27 Sep 2021 01:31:20 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: yes X-MS-TNEF-Correlator: suggested_attachment_session_id: 1a913ccc-4654-9554-6fc7-4147b2335259 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [HeYjrU9Ma66O4Ys1o1Y4DrfHQpWo6tLd] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1e824d92-bc2a-4bd9-2fc8-08d9815682ba x-ms-traffictypediagnostic: MWHPR05MB3663: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: hRIn3WNBjty3zqKRVUTsqrDu0hH3AUWKA6mUiYJ5Q55HqJRGkVTpr9hQVMsYZyHPWxxms+/7MvnLz8tlGTa3HqzqjkmM412a0EZj9sQ6zj/7LSS6impGFxk5dETMnDrg30wU6b7D8vcttBIFwdJVpV3K7NbZnNNjslJbKXjiQAt+D+BndlJP0kfO2FHaGoyrsNqqVeqN6fKH7uQuILBbZ6OWrGVvaRVHQy8z5MCs++XgvDUzTEuxI98hgzFVG/9A+nEZqyVE8TJ0t6ZGacusIz8jZ1nhutabFYAC0lgmrK7RhcLnijU2aDboWov0KpHIuNa0BpbqpukX1EqMGgD5wG9A5PY7NCNIeSxPxcZrjricKjBzRQxKRW92ncUAD2jSOrTBcupXLws1lRjQ9sZAYOI+VVsHaUTKCkxzjSLWrdTxdjmRHO3xc7CQ5iSR5rvQuR4DEuBZ2gM82FkrpVgszuAgeX3jyUwcn/6VKVj/Mpk= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: aSzyJ5d2+MIP7nnWSHbtCcEJNirdegbt5NXuz/0RdJ949Uj5M2tiLz+yeB1an1zqiXQxeG8+RWuGKFNrS/2/4exKaOqj1XPu+KEwfSLO2EieF8nGn7Bv0U8cdHBogowWX8rDfAdPe/XJB6piNfsrfQ== x-ms-exchange-transport-forked: True Content-Type: multipart/mixed; boundary="_002_DM5PR0501MB373360315B5B4A690166555EB5A79DM5PR0501MB3733_" MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-3174-8-msonline-outlook-e6bda.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MWHPR0501MB3737.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 1e824d92-bc2a-4bd9-2fc8-08d9815682ba X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Sep 2021 01:31:20.9216 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR05MB3663 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, 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: Mon, 27 Sep 2021 01:31:24 -0000 --_002_DM5PR0501MB373360315B5B4A690166555EB5A79DM5PR0501MB3733_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi Jason,=0A= =0A= 1. Thank you very much for your detailed comments for my patch and I really= appreciate it! Here is my revised patch:=0A= =0A= The root cause of this bug is that it considers reference with=0A= cv-qualifiers as an error by generating value for variable "bad_quals".=0A= However, this is not correct for case of typedef. Here I quote spec:=0A= "Cv-qualified references are ill-formed except when the cv-qualifiers=0A= are introduced through the use of a typedef-name ([dcl.typedef],=0A= [temp.param]) or decltype-specifier ([dcl.type.decltype]),=0A= in which case the cv-qualifiers are ignored."=0A= =0A= 2021-09-25 qingzhe huang =0A= =0A= gcc/cp/=0A= PR c++/101783=0A= * tree.c (cp_build_qualified_type_real):=0A= =0A= gcc/testsuite/=0A= PR c++/101783=0A= * g++.dg/parse/pr101783.C: New test.=0A= -------------- next part --------------=0A= diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c=0A= index 8840932dba2..d5c8daeb340 100644=0A= --- a/gcc/cp/tree.c=0A= +++ b/gcc/cp/tree.c=0A= @@ -1356,11 +1356,18 @@ cp_build_qualified_type_real (tree type,=0A= /* A reference or method type shall not be cv-qualified.=0A= [dcl.ref], [dcl.fct]. This used to be an error, but as of DR 295=0A= (in CD1) we always ignore extra cv-quals on functions. */=0A= +=0A= + /* Cv-qualified references are ill-formed except when the cv-qualifiers= =0A= + are introduced through the use of a typedef-name ([dcl.typedef],=0A= + [temp.param]) or decltype-specifier ([dcl.type.decltype]),=0A= + in which case the cv-qualifiers are ignored.=0A= + */=0A= if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)=0A= && (TYPE_REF_P (type)=0A= || FUNC_OR_METHOD_TYPE_P (type)))=0A= {=0A= - if (TYPE_REF_P (type))=0A= + if (TYPE_REF_P (type)=0A= + && (!typedef_variant_p (type) || FUNC_OR_METHOD_TYPE_P (type)))=0A= bad_quals |=3D type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);=0A= type_quals &=3D ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);=0A= }=0A= diff --git a/gcc/testsuite/g++.dg/parse/pr101783.C b/gcc/testsuite/g++.dg/p= arse/pr101783.C=0A= new file mode 100644=0A= index 00000000000..4e0a435dd0b=0A= --- /dev/null=0A= +++ b/gcc/testsuite/g++.dg/parse/pr101783.C=0A= @@ -0,0 +1,5 @@=0A= +template struct A{=0A= + typedef T& Type;=0A= +};=0A= +template void f(const typename A::Type){}=0A= +template <> void f(const typename A::Type){}=0A= =0A= =0A= =0A= 2. =0A= > In Jonathan's earlier reply he asked how you tested the patch; this=0A= > message still doesn't say anything about that.=0A= I communicated with Mr. Jonathan in private email, worrying my naive questi= on might pollute the public maillist. The following is major part of this c= ommunication and I attached original part in attachment. =0A= =0A= >>>How has this patch been tested? Have you bootstrapped the compiler and= =0A= >>>run the full testsuite?=0A= Here is how I am doing:=0A= a) build original 10.2.0 from scratch and make check to get both "testsuite= /gcc/gcc.sum"=0A= and "testsuite/g++/g++.sum".=0A= b) apply my patch and build from scratch and make check to get both two fil= es above.=0A= c) compare two run's *.sum files to see if there is any difference. =0A= =0A= (Later I realized there is tool "contrib/compare_tests" is a good help of= doing so.)=0A= =0A= 3. =0A= > What is the legal status of your contributions?=0A= I thought small patch didn't require assignment. However, I just sent email= to assign@gnu.org to request assignment.=0A= Alternatively, I am not sure if adding this "signoff" tag in submission wil= l help?=0A= Signed-off-by: qingzhe huang =0A= =0A= =0A= Thank you again!=0A= =0A= =0A= > On 8/28/21 07:54, nick huang via Gcc-patches wrote:=0A= > > Reference with cv-qualifiers should be ignored instead of causing an er= ror=0A= > > because standard accepts cv-qualified references introduced by typedef = which=0A= > > is ignored.=0A= > > Therefore, the fix prevents GCC from reporting error by not setting var= iable=0A= > > "bad_quals" in case the reference is introduced by typedef. Still the= =0A= > > cv-qualifier is silently ignored.=0A= > > Here I quote spec (https://timsong-cpp.github.io/cppwp/dcl.ref#1):=0A= > > "Cv-qualified references are ill-formed except when the cv-qualifiers= =0A= > > are introduced through the use of a typedef-name ([dcl.typedef],=0A= > > [temp.param]) or decltype-specifier ([dcl.type.decltype]),=0A= > > in which case the cv-qualifiers are ignored."=0A= > >=0A= > > PR c++/101783=0A= > >=0A= > > gcc/cp/ChangeLog:=0A= > >=0A= > > 2021-08-27 qingzhe huang =0A= > >=0A= > > * tree.c (cp_build_qualified_type_real):=0A= >=0A= > The git commit verifier rejects this commit message with=0A= >=0A= > Checking 1fa0fbcdd15adf936ab4fae584f841beb35da1bb: FAILED ERR: missing=0A= > description of a change:=0A= > " * tree.c (cp_build_qualified_type_real):"=0A= >=0A= > (your initial patch had a description here, you just need to copy it over= )=0A= >=0A= > ERR: PR 101783 in subject but not in changelog:=0A= > "c++: Suppress error when cv-qualified reference is introduced by=0A= > typedef [PR101783]"=0A= >=0A= > (the PR number needs to have a Tab before it)=0A= >=0A= > In Jonathan's earlier reply he asked how you tested the patch; this=0A= > message still doesn't say anything about that.=0A= >=0A= > https://gcc.gnu.org/contribute.html#testing=0A= >=0A= > What is the legal status of your contributions?=0A= >=0A= > https://gcc.gnu.org/contribute.html#legal=0A= >=0A= > Existing code tries to handle this with the tf_ignore_bad_quals, but the= =0A= > unnecessary use of typename gets past the code that tries to set the=0A= > flag. But your approach is nice and straightforward, so let's go ahead= =0A= > with it.=0A= >=0A= > > gcc/testsuite/ChangeLog:=0A= > >=0A= > > 2021-08-27 qingzhe huang =0A= > >=0A= > > * g++.dg/parse/pr101783.C: New test.=0A= > >=0A= > > diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c=0A= > > index 8840932dba2..7aa4318a574 100644=0A= > > --- a/gcc/cp/tree.c=0A= > > +++ b/gcc/cp/tree.c=0A= > > @@ -1356,12 +1356,22 @@ cp_build_qualified_type_real (tree type,=0A= > > /* A reference or method type shall not be cv-qualified.=0A= > > [dcl.ref], [dcl.fct]. This used to be an error, but as of DR 29= 5=0A= > > (in CD1) we always ignore extra cv-quals on functions. */=0A= > > +=0A= > > + /* PR 101783=0A= >=0A= > Let's cite where this comes from in the standard ([dcl.ref]/1), and not= =0A= > the PR number.=0A= >=0A= > > + Cv-qualified references are ill-formed except when the cv-qualifi= ers=0A= > > + are introduced through the use of a typedef-name ([dcl.typedef],= =0A= > > + [temp.param]) or decltype-specifier ([dcl.type.decltype]),=0A= > > + in which case the cv-qualifiers are ignored.=0A= > > + */=0A= > > if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)=0A= > > && (TYPE_REF_P (type)=0A= > > || FUNC_OR_METHOD_TYPE_P (type)))=0A= > > {=0A= > > - if (TYPE_REF_P (type))=0A= > > + // do NOT set bad_quals when non-method reference is introduced = by typedef.=0A= > > + if (TYPE_REF_P (type)=0A= > > + && (!typedef_variant_p (type) || FUNC_OR_METHOD_TYPE_P (type)))=0A= > > bad_quals |=3D type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);= =0A= > > + // non-method reference introduced by typedef is also dropped si= lently=0A= >=0A= > These two // comments seem redundant with the quote from the standard=0A= > above, let's drop them.=0A= >=0A= > > type_quals &=3D ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE);=0A= > > }=0A= > > =0A= > > diff --git a/gcc/testsuite/g++.dg/parse/pr101783.C b/gcc/testsuite/g++.= dg/parse/pr101783.C=0A= > > new file mode 100644=0A= > > index 00000000000..4e0a435dd0b=0A= > > --- /dev/null=0A= > > +++ b/gcc/testsuite/g++.dg/parse/pr101783.C=0A= > > @@ -0,0 +1,5 @@=0A= > > +template struct A{=0A= > > + typedef T& Type;=0A= > > +};=0A= > > +template void f(const typename A::Type){}=0A= > > +template <> void f(const typename A::Type){}=0A= > >=0A= > >=0A= > > = --_002_DM5PR0501MB373360315B5B4A690166555EB5A79DM5PR0501MB3733_ Content-Type: text/plain; name="how-to-test.txt" Content-Description: how-to-test.txt Content-Disposition: attachment; filename="how-to-test.txt"; size=1463; creation-date="Mon, 27 Sep 2021 01:01:56 GMT"; modification-date="Mon, 27 Sep 2021 01:01:56 GMT" Content-Transfer-Encoding: base64 PiA+Pj5Ib3cgaGFzIHRoaXMgcHRjaCBiZWVuIHRlc3RlZD8gSGF2ZSB5b3UgYm9vdHN0cmFwcGVk IHRoZSBjb21waWxlciBhbmQKPiA+Pj5ydW4gdGhlIGZ1bGwgdGVzdHN1aXRlPwo+IEhlcmUgaXMg aG93IEkgYW0gZG9pbmc6Cj4gYSkgYnVpbGQgb3JpZ2luYWwgMTAuMi4wIGZyb20gc2NyYXRjaCBh bmQgbWFrZSBjaGVjayB0byBnZXQgYm90aCAidGVzdHN1aXRlL2djYy9nY2Muc3VtIgo+IGFuZCAi dGVzdHN1aXRlL2crKy9nKysuc3VtIi4KPiBUaGlzIGlzIG15IGNvbmZpZ3VyZSBwYXJhbXM6Cj4K PiBjb25maWd1cmUgLS1wcmVmaXg9L2hvbWUvbmljay9Eb3dubG9hZHMvZ2NjLTEwLjIuMC10ZXN0 L2djY19pbnN0YWxsL2djYy0xMC4yLjBfaW5zdGFsbAoKPiAtLWVuYWJsZS1ib290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