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 78FEE3858D20 for ; Fri, 11 Aug 2023 13:54:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 78FEE3858D20 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=1691762060; 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=7KjiSimdK991ytkOciRgChxlPeXpKB6rlhqa+ImkZ40=; b=M+T17D+ZFdnpj6I2A3ewLzY4Zjpkbjkij2Z7JvPLNuiqZeY5UNpuyeMhMmCCQZP7HAVWBU MxEusF9RywFmzPcNbxceOJZ85r1e7b3qCUGCDnj8FXW8eGXnVhjrbpuFHhvEcnbPbuLK0b PyDi3MbHN5Utcs5yQCzxTDig+kdm3YA= Received: from mail-vs1-f71.google.com (mail-vs1-f71.google.com [209.85.217.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-214-8Lkhpxq4PouBQCJch9d04Q-1; Fri, 11 Aug 2023 09:54:18 -0400 X-MC-Unique: 8Lkhpxq4PouBQCJch9d04Q-1 Received: by mail-vs1-f71.google.com with SMTP id ada2fe7eead31-44793458010so826948137.2 for ; Fri, 11 Aug 2023 06:54:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691762054; x=1692366854; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lzOSmew7OCp7dr2v7at7nwtqTIhHJLoVDql+St3ezk4=; b=Rs5Jk2t4LKzBVwCShgnX80zf6lEDSRg5U39uP/9s3va2gJNEUw5AL+stHQf5SJ9zET bV4kLSMiVtkccW8bixBohWIfDVBk2VjC93m5qTOaGyLbznzSwkkDDelINoPI8g9LrxM1 1Cpo2uu6jifPCoQjONYO5tsJWQakWWokJS6m+vESLBPBcIUzheDiJ5UNnE8ILA6QK0yT m56oHMo9TVDUZQZ/FjsSJyrwDygSrHftK2tv9XIAvQKsFAWbRV+71B1zAnTizCTrVS9E OqJ6WxW3LASRm2BgAOFj1ECjVIE2MDuFUfR2MdaWMS66TKvKvN33G2e4fY5BOXbY97pB 2ImQ== X-Gm-Message-State: AOJu0Yz2boOPshiWDw1bOWYWxXLeyV5n9dudBWmk5Onm2ihTpEzgb1ex BoamGYjNo8oGgJNBi4jgTYvJP3q37UP95Dmrl+omr1I7Rsata16L1KgZAXxXWsoT5Ya9DYUdrDw gPZ7i04bp6kLy7EnZHg== X-Received: by 2002:a67:ba1a:0:b0:443:5981:72ad with SMTP id l26-20020a67ba1a000000b00443598172admr1865083vsn.24.1691762054585; Fri, 11 Aug 2023 06:54:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEkw7M7U4Njg4eJ8Lhw1MTCfASmLnZcrAMyRFEYjKdMbxL1MvLopyXPC6vyYOVM9bPsY4IU2w== X-Received: by 2002:a67:ba1a:0:b0:443:5981:72ad with SMTP id l26-20020a67ba1a000000b00443598172admr1865073vsn.24.1691762054308; Fri, 11 Aug 2023 06:54:14 -0700 (PDT) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id o13-20020a0cf4cd000000b0063f82020d8bsm1228695qvm.60.2023.08.11.06.54.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 06:54:13 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Fri, 11 Aug 2023 09:54:13 -0400 (EDT) To: Jason Merrill cc: Patrick Palka , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c++: bogus warning w/ deduction guide in anon ns [PR106604] In-Reply-To: Message-ID: References: <20230810160900.1513252-1-ppalka@redhat.com> <932df809-cf99-57ac-b285-75c7cec8f6eb@redhat.com> <7d7a92a1-145b-4a8f-914f-10bfda1e02f2@idea> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="8323329-2069279239-1691762053=:367974" 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,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: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-2069279239-1691762053=:367974 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT 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? 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; -- 2.42.0.rc1 --8323329-2069279239-1691762053=:367974--