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 56AC3385828D for ; Fri, 11 Aug 2023 14:00:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 56AC3385828D 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=1691762451; 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=+PMG0Kn0F2ZSzfVMqiB5tKSjysYJyN3f4nWN88ZJLvg=; b=iwOPood9sgK6sXn/G08JaJJF8+a2zLNS2KBNXlzQ618jFbjct/vhc1FQ7ueZQTv+As62EU 6uoro9E4RPrei9AfRCyBW1FdBCWQLIYJbaNTWa8CecBu8n+jeXn/pL2TYvOfgBlq7e0PlK HOaPbnXx9HiyB5DORTsar287+DY31rE= 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_256_GCM_SHA384) id us-mta-288-axdcJkiROEWRj3atTOuMzA-1; Fri, 11 Aug 2023 10:00:42 -0400 X-MC-Unique: axdcJkiROEWRj3atTOuMzA-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-63cd1ea05d7so26953106d6.0 for ; Fri, 11 Aug 2023 07:00:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691762435; x=1692367235; 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:message-id:reply-to; bh=+PMG0Kn0F2ZSzfVMqiB5tKSjysYJyN3f4nWN88ZJLvg=; b=aQGKDyFRtYZcHle3cAfxmIWmbHGs3AmaqjcznOsParJ8xBctAlaO8ZTmyuyM3ALwy3 z2/hr6eYCGjbReVCFxOsjx8i6xspcFWh1ZwGp2psVW8bX/LTjDVUb4tZ8mSqdRghztzZ 73q4CShfcH0USwqeXNcajJd0d3eFjT39kY7fyxgDEMBw0KUepPoP5XdPwfJiiHZZX3c6 YosoDs0XskfW7IMyxl+K6uVApWmGZa41K8V9O0yPL7a5NppEKttnNWjLOCIPlBTASL8z PYqtnNI55Xyu7pXaecbfvNQTfgvuXRUVGFOGlplWkmA524qU8jHyF6obNSOUJrBTExlh IRsw== X-Gm-Message-State: AOJu0Ywt+wvSxtUJLbgNTj1fZ7Cp6ijKO3xUg5mMvj7G+f/SZLjGhdjY HPo2/3oLHZ4mF+bI/W000qFQaHpSslWxQ4bvBbizrad+cF+99BKovv8K5MAYZd5iMxy2AI7TF0U LdjJiy3Yg2DM8LMZjU7I/28p0EA== X-Received: by 2002:a0c:b30a:0:b0:636:1d3f:3d77 with SMTP id s10-20020a0cb30a000000b006361d3f3d77mr2202085qve.14.1691762435092; Fri, 11 Aug 2023 07:00:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGv+EKfyCeM1sY/zUBcOInLv+iE9CerF4N6Yqcjn8Tg2rX6uKtwLP5SFjWmlEkZPMP4eHt6WQ== X-Received: by 2002:a0c:b30a:0:b0:636:1d3f:3d77 with SMTP id s10-20020a0cb30a000000b006361d3f3d77mr2202054qve.14.1691762434727; Fri, 11 Aug 2023 07:00:34 -0700 (PDT) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id f5-20020a0ccc85000000b0063cdbe739f0sm1235044qvl.71.2023.08.11.07.00.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 11 Aug 2023 07:00:34 -0700 (PDT) Message-ID: Date: Fri, 11 Aug 2023 10:00:33 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH] c++: bogus warning w/ deduction guide in anon ns [PR106604] To: Patrick Palka Cc: gcc-patches@gcc.gnu.org References: <20230810160900.1513252-1-ppalka@redhat.com> <932df809-cf99-57ac-b285-75c7cec8f6eb@redhat.com> <7d7a92a1-145b-4a8f-914f-10bfda1e02f2@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: 8bit X-Spam-Status: No, score=-13.0 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,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,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 8/11/23 09:54, Patrick Palka wrote: > On Thu, 10 Aug 2023, Jason Merrill wrote: > >> On 8/10/23 16:40, Patrick Palka wrote: >>> On Thu, 10 Aug 2023, Jason Merrill wrote: >>> >>>> On 8/10/23 12:09, Patrick Palka wrote: >>>>> Booststrapped and regtested on x86_64-pc-linux-gnu, does this look OK >>>>> for >>>>> trunk and perhaps 13? >>>>> >>>>> -- >8 -- >>>>> >>>>> We shouldn't issue a "declared static but never defined" warning >>>>> for a deduction guide (declared in an anonymous namespace). >>>>> >>>>> PR c++/106604 >>>>> >>>>> gcc/cp/ChangeLog: >>>>> >>>>> * decl.cc (wrapup_namespace_globals): Don't issue a >>>>> -Wunused-function warning for a deduction guide. >>>> >>>> Maybe instead of special casing this here we could set DECL_INITIAL on >>>> deduction guides so they look defined? >>> >>> That seems to work, but it requires some tweaks in duplicate_decls to keep >>> saying "declared" instead of "defined" when diagnosing a deduction guide >>> redeclaration. I'm not sure which approach is preferable? >> >> I'm not sure it matters which we say; the restriction that you can't repeat a >> deduction guide makes it more like a definition anyway (even if [basic.def] >> disagrees). Is the diagnostic worse apart from that word? > > Ah, makes sense. So we can also remove the special case for them in the > redeclaration checking code after we give them a dummy DECL_INITIAL. > Like so? OK, thanks. > Here's a before/after for the diagnostic with the below patch: > > Before > > src/gcc/testsuite/g++.dg/cpp1z/class-deduction74.C:11:1: error: deduction guide ‘S()-> S’ redeclared > 11 | S() -> S; // { dg-error "redefinition" } > | ^ > src/gcc/testsuite/g++.dg/cpp1z/class-deduction74.C:10:1: note: ‘S()-> S’ previously declared here > 10 | S() -> S; // { dg-message "previously defined here|old declaration" } > | ^ > > After > > src/gcc/testsuite/g++.dg/cpp1z/class-deduction74.C:11:1: error: redefinition of ‘S()-> S’ > 11 | S() -> S; // { dg-error "redefinition" } > | ^ > src/gcc/testsuite/g++.dg/cpp1z/class-deduction74.C:10:1: note: ‘S()-> S’ previously defined here > 10 | S() -> S; // { dg-message "previously defined here|old declaration" } > | ^ > > -- >8 -- > > Subject: [PATCH] c++: bogus warning w/ deduction guide in anon ns [PR106604] > > Here we're unintentionally issuing a "declared static but never defined" > warning for a deduction guide declared in an anonymous namespace. > This patch fixes this by giving deduction guides a dummy DECL_INITIAL, > which suppresses the warning and also allows us to simplify redeclaration > checking for them. > > Co-authored-by: Jason Merrill > > PR c++/106604 > > gcc/cp/ChangeLog: > > * decl.cc (redeclaration_error_message): Remove special handling > for deduction guides. > (grokfndecl): Give deduction guides a dummy DECL_INITIAL. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp1z/class-deduction74.C: Expect "defined" instead > of "declared" in diagnostics for a repeated deduction guide. > * g++.dg/cpp1z/class-deduction116.C: New test. > --- > gcc/cp/decl.cc | 14 ++++++-------- > gcc/testsuite/g++.dg/cpp1z/class-deduction116.C | 8 ++++++++ > gcc/testsuite/g++.dg/cpp1z/class-deduction74.C | 14 +++++++------- > 3 files changed, 21 insertions(+), 15 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp1z/class-deduction116.C > > diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc > index 792ab330dd0..3ada5516c58 100644 > --- a/gcc/cp/decl.cc > +++ b/gcc/cp/decl.cc > @@ -3297,10 +3297,6 @@ redeclaration_error_message (tree newdecl, tree olddecl) > } > } > > - if (deduction_guide_p (olddecl) > - && deduction_guide_p (newdecl)) > - return G_("deduction guide %q+D redeclared"); > - > /* [class.compare.default]: A definition of a comparison operator as > defaulted that appears in a class shall be the first declaration of > that function. */ > @@ -3355,10 +3351,6 @@ redeclaration_error_message (tree newdecl, tree olddecl) > } > } > > - if (deduction_guide_p (olddecl) > - && deduction_guide_p (newdecl)) > - return G_("deduction guide %q+D redeclared"); > - > /* Core issue #226 (C++11): > > If a friend function template declaration specifies a > @@ -10352,6 +10344,12 @@ grokfndecl (tree ctype, > DECL_CXX_DESTRUCTOR_P (decl) = 1; > DECL_NAME (decl) = dtor_identifier; > break; > + case sfk_deduction_guide: > + /* Give deduction guides a definition even though they don't really > + have one: the restriction that you can't repeat a deduction guide > + makes them more like a definition anyway. */ > + DECL_INITIAL (decl) = void_node; > + break; > default: > break; > } > diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction116.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction116.C > new file mode 100644 > index 00000000000..00f6d5fef41 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction116.C > @@ -0,0 +1,8 @@ > +// PR c++/106604 > +// { dg-do compile { target c++17 } } > +// { dg-additional-options "-Wunused-function" } > + > +namespace { > + template struct A { A(...); }; > + A(bool) -> A; // { dg-bogus "never defined" } > +} > diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction74.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction74.C > index fe113819a95..7bab882da7d 100644 > --- a/gcc/testsuite/g++.dg/cpp1z/class-deduction74.C > +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction74.C > @@ -7,20 +7,20 @@ > template struct S { }; > template struct X { }; > > -S() -> S; // { dg-message "previously declared here|old declaration" } > -S() -> S; // { dg-error "redeclared" } > +S() -> S; // { dg-message "previously defined here|old declaration" } > +S() -> S; // { dg-error "redefinition" } > X() -> X; > S() -> S; // { dg-error "ambiguating new declaration of" } > > -S(bool) -> S; // { dg-message "previously declared here" } > -explicit S(bool) -> S; // { dg-error "redeclared" } > +S(bool) -> S; // { dg-message "previously defined here" } > +explicit S(bool) -> S; // { dg-error "redefinition" } > > -explicit S(char) -> S; // { dg-message "previously declared here" } > -S(char) -> S; // { dg-error "redeclared" } > +explicit S(char) -> S; // { dg-message "previously defined here" } > +S(char) -> S; // { dg-error "redefinition" } > > template S(T, T) -> S; // { dg-message "previously declared here" } > template X(T, T) -> X; > -template S(T, T) -> S; // { dg-error "redeclared" } > +template S(T, T) -> S; // { dg-error "redefinition" } > > // OK: Use SFINAE. > template S(T) -> S;