From: Volker Reichelt Date: Fri, 2 Sep 2005 09:25:13 +0000 (+0000) Subject: Backport: X-Git-Tag: releases/gcc-3.4.5~216 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=00581080d842fe18b49960f1d757d0d9b1f4c527;p=thirdparty%2Fgcc.git Backport: 2004-11-25 Mark Mitchell PR c++/18466 * decl.c (grokvardecl): Keep track of whether or not a there was explicit qualification. * name-lookup.c (set_decl_namespace): Complain about explicit qualification of a name within its own namespace. * g++.dg/parse/qualified3.C: New test. * g++.old-deja/g++.other/friend7.C: Remove bogus qualification. 2004-11-29 Ben Elliston * g++.old-deja/g++.other/decl5.C: Remove remaining XFAILs. From-SVN: r103768 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 211c9db75cc0..231698e8a674 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,14 @@ +2005-09-02 Volker Reichelt + + Backport: + + 2004-11-25 Mark Mitchell + PR c++/18466 + * decl.c (grokvardecl): Keep track of whether or not a there was + explicit qualification. + * name-lookup.c (set_decl_namespace): Complain about explicit + qualification of a name within its own namespace. + 2005-09-02 Volker Reichelt Backport: diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 3f62ad5540d0..85aed90aee06 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5903,6 +5903,7 @@ grokvardecl (tree type, tree scope) { tree decl; + tree explicit_scope; RID_BIT_TYPE specbits; my_friendly_assert (!name || TREE_CODE (name) == IDENTIFIER_NODE, @@ -5910,7 +5911,9 @@ grokvardecl (tree type, specbits = *specbits_in; - /* Compute the scope in which to place the variable. */ + /* Compute the scope in which to place the variable, but remember + whether or not that scope was explicitly specified by the user. */ + explicit_scope = scope; if (!scope) { /* An explicit "extern" specifier indicates a namespace-scope @@ -5939,8 +5942,8 @@ grokvardecl (tree type, else decl = build_decl (VAR_DECL, name, type); - if (scope && TREE_CODE (scope) == NAMESPACE_DECL) - set_decl_namespace (decl, scope, 0); + if (explicit_scope && TREE_CODE (explicit_scope) == NAMESPACE_DECL) + set_decl_namespace (decl, explicit_scope, 0); else DECL_CONTEXT (decl) = scope; diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index dab2b5787750..00a2f8f4e459 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -3021,7 +3021,13 @@ set_decl_namespace (tree decl, tree scope, bool friendp) return; } else - return; + { + /* Writing "int N::i" to declare a variable within "N" is invalid. */ + if (at_namespace_scope_p ()) + error ("explicit qualification in declaration of `%D'", decl); + return; + } + complain: error ("`%D' should have been declared inside `%D'", decl, scope); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 764e589c2ea0..674838ccc102 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,15 @@ +2005-09-02 Volker Reichelt + + Backport: + + 2004-11-25 Mark Mitchell + PR c++/18466 + * g++.dg/parse/qualified3.C: New test. + * g++.old-deja/g++.other/friend7.C: Remove bogus qualification. + + 2004-11-29 Ben Elliston + * g++.old-deja/g++.other/decl5.C: Remove remaining XFAILs. + 2005-09-02 Volker Reichelt Backport: diff --git a/gcc/testsuite/g++.old-deja/g++.other/decl5.C b/gcc/testsuite/g++.old-deja/g++.other/decl5.C index 4aa1647548a7..f8c447c01d3b 100644 --- a/gcc/testsuite/g++.old-deja/g++.other/decl5.C +++ b/gcc/testsuite/g++.old-deja/g++.other/decl5.C @@ -52,8 +52,8 @@ namespace N { namespace NMS { - void NMS::fn(); // { dg-warning "" "" { xfail *-*-* } } extra qualification - int NMS::i; // { dg-warning "" "" { xfail *-*-* } } extra qualification + void NMS::fn(); // { dg-warning "" "" } extra qualification + int NMS::i; // { dg-warning "" "" } extra qualification struct NMS::D { // { dg-warning "" } extra qualification int i; }; diff --git a/gcc/testsuite/g++.old-deja/g++.other/friend7.C b/gcc/testsuite/g++.old-deja/g++.other/friend7.C index 1055d99ceae7..aed56a187ddf 100644 --- a/gcc/testsuite/g++.old-deja/g++.other/friend7.C +++ b/gcc/testsuite/g++.old-deja/g++.other/friend7.C @@ -15,7 +15,7 @@ class S { }; } -void (::foo)(M::S *ptr) { +void (foo)(M::S *ptr) { M::S::s.Fn(); ptr->Fn(); }