From 273aa49e2fe00de54cb1dbe67f1a6155fb47439b Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Wed, 9 Sep 2015 16:48:13 +0000 Subject: re PR c++/53184 (Unnecessary anonymous namespace warnings) 2015-09-09 Paolo Carlini PR c++/53184 * doc/invoke.texi ([Wsubobject-linkage]): Document. /c-family 2015-09-09 Paolo Carlini PR c++/53184 * c.opt ([Wsubobject-linkage]): Add. /cp 2015-09-09 Paolo Carlini PR c++/53184 * decl2.c (constrain_class_visibility): Use Wsubobject-linkage. /testsuite 2015-09-09 Paolo Carlini PR c++/53184 * g++.dg/warn/Wsubobject-linkage-1.C: New. * g++.dg/warn/Wsubobject-linkage-2.C: Likewise. * g++.dg/warn/Wsubobject-linkage-3.C: Likewise. * g++.dg/warn/Wsubobject-linkage-4.C: Likewise. From-SVN: r227593 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/decl2.c | 40 +++++++++++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 5 deletions(-) (limited to 'gcc/cp') diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 515a1e8..1cc576a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2015-09-09 Paolo Carlini + + PR c++/53184 + * decl2.c (constrain_class_visibility): Use Wsubobject-linkage. + 2015-09-09 Jakub Jelinek PR c++/67504 diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 74ba380..6c1f084 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -2564,10 +2564,25 @@ constrain_class_visibility (tree type) if (subvis == VISIBILITY_ANON) { - if (!in_main_input_context ()) - warning (0, "\ + if (!in_main_input_context()) + { + tree nlt = no_linkage_check (ftype, /*relaxed_p=*/false); + if (nlt) + { + if (same_type_p (TREE_TYPE (t), nlt)) + warning (OPT_Wsubobject_linkage, "\ +%qT has a field %qD whose type has no linkage", + type, t); + else + warning (OPT_Wsubobject_linkage, "\ +%qT has a field %qD whose type depends on the type %qT which has no linkage", + type, t, nlt); + } + else + warning (OPT_Wsubobject_linkage, "\ %qT has a field %qD whose type uses the anonymous namespace", - type, t); + type, t); + } } else if (MAYBE_CLASS_TYPE_P (ftype) && vis < VISIBILITY_HIDDEN @@ -2585,9 +2600,24 @@ constrain_class_visibility (tree type) if (subvis == VISIBILITY_ANON) { if (!in_main_input_context()) - warning (0, "\ + { + tree nlt = no_linkage_check (TREE_TYPE (t), /*relaxed_p=*/false); + if (nlt) + { + if (same_type_p (TREE_TYPE (t), nlt)) + warning (OPT_Wsubobject_linkage, "\ +%qT has a base %qT whose type has no linkage", + type, TREE_TYPE (t)); + else + warning (OPT_Wsubobject_linkage, "\ +%qT has a base %qT whose type depends on the type %qT which has no linkage", + type, TREE_TYPE (t), nlt); + } + else + warning (OPT_Wsubobject_linkage, "\ %qT has a base %qT whose type uses the anonymous namespace", - type, TREE_TYPE (t)); + type, TREE_TYPE (t)); + } } else if (vis < VISIBILITY_HIDDEN && subvis >= VISIBILITY_HIDDEN) -- cgit v1.1