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.129.124]) by sourceware.org (Postfix) with ESMTPS id 47C1238346A9 for ; Fri, 22 Jul 2022 11:20:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 47C1238346A9 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-613-gYVXRnoMNfSrzYos-JRvSg-1; Fri, 22 Jul 2022 07:20:26 -0400 X-MC-Unique: gYVXRnoMNfSrzYos-JRvSg-1 Received: by mail-qk1-f199.google.com with SMTP id ay35-20020a05620a17a300b006b5d9646d31so3502079qkb.6 for ; Fri, 22 Jul 2022 04:20:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RVD7+4MAAztWUis1jm3N/xLmxaOKQ7e52KzECUn7N24=; b=mxHHg1LUpPOhbUdeiyJ7H0KrchsvFLnvzATb/vTv/8m1X3XWBLcexlE6nOi9E6jfGk Xzhrn66hgc2l7uyUCPdV4o/1lcskzNWDdTHSROd4TtCZDTL3lfWaHOPAnnnmyzpFgkhW x7aiVsDpHHRWw9BG4sTkLF6szF21E49W7hT9aXvLog89541hhyxQkcU1Xj9a3U5N7WIL fx/5akLTc7WK7YqaL6GahHkhjqPRB064PJwoVdDFpkLMpZGo+w6xYZZiOcow2/xqhn1i VDG3CoWzfL3kWpF+EWLISyPDWbvYwzOJ7cYglhepO1CnF8N/NWyva7RDYnkIMTdRZcLO SfHA== X-Gm-Message-State: AJIora+UwrmFBZmiBdnlBBNS/olf8SlqfJZ19a0MTDJ81VWwG33rxEmm a+QEzdU7RzDVHRvrK3wBV/8aUGchz8GC1TlMQRlQVBC/qlzKswNeA9EP4iOqaLy7M0IWNjZ9b9I zxZWaYWpZ1TAWWjKOe/FIeMngydnpGdWlcA== X-Received: by 2002:a05:620a:f8f:b0:6b5:be6c:255e with SMTP id b15-20020a05620a0f8f00b006b5be6c255emr100122qkn.638.1658488825535; Fri, 22 Jul 2022 04:20:25 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tSDWWu0FD/zOPcvpvEaHmsiZVFVrduPJO42n8QBgG9gziN4z5ar21RLCFeIPisoiU+/QXRukMOhpO6dzjKtrA= X-Received: by 2002:a05:620a:f8f:b0:6b5:be6c:255e with SMTP id b15-20020a05620a0f8f00b006b5be6c255emr100103qkn.638.1658488825224; Fri, 22 Jul 2022 04:20:25 -0700 (PDT) MIME-Version: 1.0 References: <20220630165326.1253733-1-jwakely@redhat.com> In-Reply-To: <20220630165326.1253733-1-jwakely@redhat.com> From: Jonathan Wakely Date: Fri, 22 Jul 2022 12:20:14 +0100 Message-ID: Subject: Re: [PATCH] c++: Refer to internal linkage for -Wsubobject-linkage [PR86491] To: gcc-patches@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, 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 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: Fri, 22 Jul 2022 11:20:30 -0000 ping https://gcc.gnu.org/pipermail/gcc-patches/2022-June/597560.html On Thu, 30 Jun 2022 at 17:53, Jonathan Wakely wrote: > > Tested powerpc64le-linux, OK for trunk? > > -- >8 -- > > Since C++11 relaxed the requirement for template arguments to have > external linkage, it's possible to get -Wsubobject-linkage warnings > without using any anonymous namespaces. This confuses users when they > get diagnostics that refer to an anonymous namespace that doesn't exist > in their code. > > This changes the diagnostic to say "has internal linkage" for C++11 and > later, which is accurate whether internal linkage is due to the 'static' > specifier, or due to the use of anonymous namespaces. > > For C++98 template arguments declared with 'static' are ill-formed > anyway, so the only way this warning can arise is via anonymous > namespaces. That means the existing wording is accurate for C++98 and so > we can keep it. > > PR c++/86491 > > gcc/cp/ChangeLog: > > * decl2.cc (constrain_class_visibility): Adjust wording of > -Wsubobject-linkage to account for cases where anonymous > namespaces aren't used. > > gcc/testsuite/ChangeLog: > > * g++.dg/warn/Wsubobject-linkage-3.C: Adjust for new warning. > * g++.dg/warn/anonymous-namespace-1.C: Use separate dg-warning > directives for C++98 and everything else. > * g++.dg/warn/anonymous-namespace-2.C: Likewise. > * g++.dg/warn/anonymous-namespace-3.C: Likewise. > --- > gcc/cp/decl2.cc | 12 ++++++++++-- > gcc/testsuite/g++.dg/warn/Wsubobject-linkage-3.C | 4 ++-- > gcc/testsuite/g++.dg/warn/anonymous-namespace-1.C | 8 ++++++-- > gcc/testsuite/g++.dg/warn/anonymous-namespace-2.C | 9 ++++++--- > gcc/testsuite/g++.dg/warn/anonymous-namespace-3.C | 3 ++- > 5 files changed, 26 insertions(+), 10 deletions(-) > > diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc > index 3737e5f010c..de53678715e 100644 > --- a/gcc/cp/decl2.cc > +++ b/gcc/cp/decl2.cc > @@ -3027,7 +3027,11 @@ constrain_class_visibility (tree type) > %qT has a field %qD whose type depends on the type %qT which has no linkage", > type, t, nlt); > } > - else > + else if (cxx_dialect > cxx98) > + warning (OPT_Wsubobject_linkage, "\ > +%qT has a field %qD whose type has internal linkage", > + type, t); > + else // In C++98 this can only happen with unnamed namespaces. > warning (OPT_Wsubobject_linkage, "\ > %qT has a field %qD whose type uses the anonymous namespace", > type, t); > @@ -3062,7 +3066,11 @@ constrain_class_visibility (tree type) > %qT has a base %qT whose type depends on the type %qT which has no linkage", > type, TREE_TYPE (t), nlt); > } > - else > + else if (cxx_dialect > cxx98) > + warning (OPT_Wsubobject_linkage, "\ > +%qT has a base %qT whose type has internal linkage", > + type, TREE_TYPE (t)); > + else // In C++98 this can only happen with unnamed namespaces. > warning (OPT_Wsubobject_linkage, "\ > %qT has a base %qT whose type uses the anonymous namespace", > type, TREE_TYPE (t)); > diff --git a/gcc/testsuite/g++.dg/warn/Wsubobject-linkage-3.C b/gcc/testsuite/g++.dg/warn/Wsubobject-linkage-3.C > index 95a04501441..b116fbbb186 100644 > --- a/gcc/testsuite/g++.dg/warn/Wsubobject-linkage-3.C > +++ b/gcc/testsuite/g++.dg/warn/Wsubobject-linkage-3.C > @@ -3,7 +3,7 @@ > namespace { struct Foo { }; } > > #line 6 "foo.C" > -struct Bar { Foo foo; }; // { dg-warning "anonymous namespace" } > +struct Bar { Foo foo; }; // { dg-warning "anonymous namespace|internal linkage" } > // { dg-bogus "no linkage" "" { target *-*-* } .-1 } > -struct Bar2 : Foo { }; // { dg-warning "anonymous namespace" } > +struct Bar2 : Foo { }; // { dg-warning "anonymous namespace|internal linkage" } > // { dg-bogus "no linkage" "" { target *-*-* } .-1 } > diff --git a/gcc/testsuite/g++.dg/warn/anonymous-namespace-1.C b/gcc/testsuite/g++.dg/warn/anonymous-namespace-1.C > index cf193e0cba5..eed3818c5cf 100644 > --- a/gcc/testsuite/g++.dg/warn/anonymous-namespace-1.C > +++ b/gcc/testsuite/g++.dg/warn/anonymous-namespace-1.C > @@ -14,5 +14,9 @@ class foobar1 > }; > > #line 17 "foo.C" > -class foobar : public bad { }; // { dg-warning "uses the anonymous namespace" } > -class foobar2 { bad b; }; // { dg-warning "uses the anonymous namespace" } > +class foobar : public bad { }; > +// { dg-warning "has internal linkage" "" { target c++11 } .-1 } > +// { dg-warning "uses the anonymous namespace" "" { target c++98_only } .-2 } > +class foobar2 { bad b; }; > +// { dg-warning "has internal linkage" "" { target c++11 } .-1 } > +// { dg-warning "uses the anonymous namespace" "" { target c++98_only } .-2 } > diff --git a/gcc/testsuite/g++.dg/warn/anonymous-namespace-2.C b/gcc/testsuite/g++.dg/warn/anonymous-namespace-2.C > index 4048f3959df..f2ca5915278 100644 > --- a/gcc/testsuite/g++.dg/warn/anonymous-namespace-2.C > +++ b/gcc/testsuite/g++.dg/warn/anonymous-namespace-2.C > @@ -18,12 +18,15 @@ struct g3 { > }; > > #line 21 "foo.C" > -struct b1 { // { dg-warning "uses the anonymous namespace" } > +struct b1 { // { dg-warning "has internal linkage" "" { target c++11 } } > +// { dg-warning "uses the anonymous namespace" "" { target c++98_only } .-1 } > bad * B; > }; > -struct b2 { // { dg-warning "uses the anonymous namespace" } > +struct b2 { // { dg-warning "has internal linkage" "" { target c++11 } } > +// { dg-warning "uses the anonymous namespace" "" { target c++98_only } .-1 } > bad * B[1]; > }; > -struct b3 { // { dg-warning "uses the anonymous namespace" } > +struct b3 { // { dg-warning "has internal linkage" "" { target c++11 } } > +// { dg-warning "uses the anonymous namespace" "" { target c++98_only } .-1 } > bad (*B)[1]; > }; > diff --git a/gcc/testsuite/g++.dg/warn/anonymous-namespace-3.C b/gcc/testsuite/g++.dg/warn/anonymous-namespace-3.C > index 8b72abdf5d1..ce5745b25f0 100644 > --- a/gcc/testsuite/g++.dg/warn/anonymous-namespace-3.C > +++ b/gcc/testsuite/g++.dg/warn/anonymous-namespace-3.C > @@ -7,7 +7,8 @@ > struct B { std::auto_ptr p; }; > > #line 10 "foo.C" > -struct C // { dg-warning "uses the anonymous namespace" } > +struct C // { dg-warning "has internal linkage" "" { target c++11 } } > +// { dg-warning "uses the anonymous namespace" "" { target c++98_only } .-1 } > { > std::auto_ptr p; > }; > -- > 2.36.1 >