]> git.ipfire.org Git - people/ms/gcc.git/commit
c++: Refer to internal linkage for -Wsubobject-linkage [PR86491]
authorJonathan Wakely <jwakely@redhat.com>
Thu, 30 Jun 2022 16:53:26 +0000 (17:53 +0100)
committerJason Merrill <jason@redhat.com>
Mon, 12 Sep 2022 16:09:44 +0000 (12:09 -0400)
commit8ef5fa4c56c82dfbd6e8fc5e4e08c4be843abc3e
treec1b43b01f3079e3a6f0667338a1152cfc80b0d4d
parent2e7bc76d84f0aa2f08bc01407ffcdca43c15f2ff
c++: Refer to internal linkage for -Wsubobject-linkage [PR86491]

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, if the type isn't actually a member of the anonymous namespace.
Making that distinction involved renaming the current decl_anon_ns_mem_p to
something that better expresses its semantics.

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 for cases where anonymous
namespaces aren't used.
* tree.cc (decl_anon_ns_mem_p): Now only true for actual anonymous
namespace members, rename old semantics to...
(decl_internal_context_p): ...this.
* cp-tree.h, name-lookup.cc, pt.cc: Adjust.

gcc/testsuite/ChangeLog:

* g++.dg/warn/anonymous-namespace-3.C: Use separate dg-warning
directives for C++98 and everything else.
* g++.dg/warn/Wsubobject-linkage-5.C: New test.
gcc/cp/cp-tree.h
gcc/cp/decl2.cc
gcc/cp/name-lookup.cc
gcc/cp/pt.cc
gcc/cp/tree.cc
gcc/testsuite/g++.dg/warn/Wsubobject-linkage-5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/anonymous-namespace-3.C