From 848bf3dc94235dac18447b00d626928c896b2057 Mon Sep 17 00:00:00 2001 From: jason Date: Thu, 26 Jan 2006 22:29:12 +0000 Subject: [PATCH] PR c++/16021 * name-lookup.c (parse_using_directive): Require strong using to name a nested namespace. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@110282 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/name-lookup.c | 11 ++++++++--- gcc/testsuite/g++.dg/lookup/strong-using-1.C | 6 +++--- gcc/testsuite/g++.dg/lookup/strong-using-2.C | 12 ++++++------ gcc/testsuite/g++.dg/lookup/strong-using-3.C | 6 +++--- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9dea52e097b..741d3de0a0e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2006-01-26 Jason Merrill + + PR c++/16021 + * name-lookup.c (parse_using_directive): Require strong using to + name a nested namespace. + 2006-01-25 Volker Reichelt Revert: diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index e0ee7a2a4e1..2f33b096d4e 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -3295,9 +3295,14 @@ parse_using_directive (tree namespace, tree attribs) if (!toplevel_bindings_p ()) error ("strong using only meaningful at namespace scope"); else if (namespace != error_mark_node) - DECL_NAMESPACE_ASSOCIATIONS (namespace) - = tree_cons (current_namespace, 0, - DECL_NAMESPACE_ASSOCIATIONS (namespace)); + { + if (!is_ancestor (current_namespace, namespace)) + error ("current namespace %qD does not enclose strongly used namespace %qD", + current_namespace, namespace); + DECL_NAMESPACE_ASSOCIATIONS (namespace) + = tree_cons (current_namespace, 0, + DECL_NAMESPACE_ASSOCIATIONS (namespace)); + } } else warning (OPT_Wattributes, "%qD attribute directive ignored", name); diff --git a/gcc/testsuite/g++.dg/lookup/strong-using-1.C b/gcc/testsuite/g++.dg/lookup/strong-using-1.C index 3d63f25b8b2..a16fd6a50b9 100644 --- a/gcc/testsuite/g++.dg/lookup/strong-using-1.C +++ b/gcc/testsuite/g++.dg/lookup/strong-using-1.C @@ -2,10 +2,10 @@ // { dg-do compile } -namespace foo { - template void swap(T, T); -} namespace fool { + namespace foo { + template void swap(T, T); + } using namespace foo __attribute__((strong)); template void swap(T); } diff --git a/gcc/testsuite/g++.dg/lookup/strong-using-2.C b/gcc/testsuite/g++.dg/lookup/strong-using-2.C index f8b5f64fbd2..21e47cba014 100644 --- a/gcc/testsuite/g++.dg/lookup/strong-using-2.C +++ b/gcc/testsuite/g++.dg/lookup/strong-using-2.C @@ -2,16 +2,16 @@ // { dg-do compile } -namespace foo_impl { - class T; // { dg-error "T" "" } -} -namespace bar_impl { - class T; // { dg-error "T" "" } -} namespace foo { + namespace foo_impl { + class T; // { dg-error "T" "" } + } using namespace foo_impl __attribute__((strong)); } namespace bar { + namespace bar_impl { + class T; // { dg-error "T" "" } + } using namespace bar_impl __attribute__((strong)); using namespace foo; } diff --git a/gcc/testsuite/g++.dg/lookup/strong-using-3.C b/gcc/testsuite/g++.dg/lookup/strong-using-3.C index 2ea538e3b1f..9b4d3c3ffea 100644 --- a/gcc/testsuite/g++.dg/lookup/strong-using-3.C +++ b/gcc/testsuite/g++.dg/lookup/strong-using-3.C @@ -2,10 +2,10 @@ // { dg-do compile } -namespace foo { - template void f(T, T); -} namespace bar { + namespace foo { + template void f(T, T); + } using namespace foo __attribute__((strong)); template void f(T); } -- 2.11.4.GIT