From: Gabriel Dos Reis Date: Sun, 11 Jan 2004 00:56:01 +0000 (+0000) Subject: re PR c++/13544 ("conflicting types" for enums in different scopes) X-Git-Tag: releases/gcc-3.3.3~109 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1897b1cc71583c432c18586cbdfa15068f6a573e;p=thirdparty%2Fgcc.git re PR c++/13544 ("conflicting types" for enums in different scopes) PR c++/13544 * decl.c (build_enumerator): Set DECL_CONTEXT after the enumerator has been pushed. (pushdecl): Don't use DECL_NAMESPACE_SCOPE_P to test whether a decl has a namespace-scope; that isn't really what it means. From-SVN: r75666 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index bdcaa9f3188d..66682f9ccecc 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2004-01-11 Gabriel Dos Reis + + PR c++/13544 + * decl.c (build_enumerator): Set DECL_CONTEXT after the enumerator + has been pushed. + (pushdecl): Don't use DECL_NAMESPACE_SCOPE_P to test whether a + decl has a namespace-scope; that isn't really what it means. + 2004-01-02 Matthias Klose Backport from mainline: diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index f2b3589c64e4..a70e9941a040 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -4142,8 +4142,9 @@ pushdecl (x) /* In case this decl was explicitly namespace-qualified, look it up in its namespace context. */ - if (DECL_NAMESPACE_SCOPE_P (x) && namespace_bindings_p ()) - t = namespace_binding (name, DECL_CONTEXT (x)); + if ((DECL_CONTEXT (x) && TREE_CODE (DECL_CONTEXT (x)) == NAMESPACE_DECL) + && namespace_bindings_p ()) + t = namespace_binding (name, DECL_CONTEXT (x)); else t = lookup_name_current_level (name); @@ -14185,7 +14186,6 @@ build_enumerator (name, value, enumtype) a function could mean local to a class method. */ decl = build_decl (CONST_DECL, name, type); - DECL_CONTEXT (decl) = FROB_CONTEXT (context); DECL_INITIAL (decl) = value; TREE_READONLY (decl) = 1; @@ -14195,7 +14195,14 @@ build_enumerator (name, value, enumtype) things like `S::i' later.) */ finish_member_declaration (decl); else - pushdecl (decl); + { + pushdecl (decl); + /* Contrary to finish_member_declaration, pushdecl does not properly + set the DECL_CONTEXT. Do that now here. Doing that before calling + pushdecl will confuse the logic used in that function. Hopefully, + future versions will implement a more straight logic. */ + DECL_CONTEXT (decl) = FROB_CONTEXT (context); + } /* Add this enumeration constant to the list for this type. */ TYPE_VALUES (enumtype) = tree_cons (name, decl, TYPE_VALUES (enumtype)); diff --git a/gcc/testsuite/g++.dg/lookup/enum1.C b/gcc/testsuite/g++.dg/lookup/enum1.C new file mode 100644 index 000000000000..e812925b6e06 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/enum1.C @@ -0,0 +1,9 @@ +enum Enum1 { None }; + +namespace Test { + enum Enum2 { None }; +} + +namespace a { + enum { a } ; +};