aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/tree.cc
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2022-06-30 17:53:26 +0100
committerJason Merrill <jason@redhat.com>2022-09-12 12:09:44 -0400
commit8ef5fa4c56c82dfbd6e8fc5e4e08c4be843abc3e (patch)
treec1b43b01f3079e3a6f0667338a1152cfc80b0d4d /gcc/cp/tree.cc
parent2e7bc76d84f0aa2f08bc01407ffcdca43c15f2ff (diff)
downloadgcc-8ef5fa4c56c82dfbd6e8fc5e4e08c4be843abc3e.zip
gcc-8ef5fa4c56c82dfbd6e8fc5e4e08c4be843abc3e.tar.gz
gcc-8ef5fa4c56c82dfbd6e8fc5e4e08c4be843abc3e.tar.bz2
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.
Diffstat (limited to 'gcc/cp/tree.cc')
-rw-r--r--gcc/cp/tree.cc12
1 files changed, 10 insertions, 2 deletions
diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index c678e3b..6de208a 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -2968,7 +2968,7 @@ verify_stmt_tree (tree t)
/* Check if the type T depends on a type with no linkage and if so,
return it. If RELAXED_P then do not consider a class type declared
within a vague-linkage function to have no linkage. Remember:
- no-linkage is not the same as internal-linkage*/
+ no-linkage is not the same as internal-linkage. */
tree
no_linkage_check (tree t, bool relaxed_p)
@@ -3817,7 +3817,15 @@ decl_namespace_context (tree decl)
nested, or false otherwise. */
bool
-decl_anon_ns_mem_p (const_tree decl)
+decl_anon_ns_mem_p (tree decl)
+{
+ return !TREE_PUBLIC (decl_namespace_context (decl));
+}
+
+/* Returns true if the enclosing scope of DECL has internal or no linkage. */
+
+bool
+decl_internal_context_p (const_tree decl)
{
while (TREE_CODE (decl) != NAMESPACE_DECL)
{