]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/13544 ("conflicting types" for enums in different scopes)
authorGabriel Dos Reis <gdr@integrable-solutions.net>
Sun, 11 Jan 2004 00:56:01 +0000 (00:56 +0000)
committerGabriel Dos Reis <gdr@gcc.gnu.org>
Sun, 11 Jan 2004 00:56:01 +0000 (00:56 +0000)
        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

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/g++.dg/lookup/enum1.C [new file with mode: 0644]

index bdcaa9f3188d18172e585f7ce7e4167f1eb57192..66682f9ccecccb23c3ffb91a78e2071eefed52a7 100644 (file)
@@ -1,3 +1,11 @@
+2004-01-11  Gabriel Dos Reis <gdr@integrable-solutions.net>
+
+       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  <doko@debian.org>
 
        Backport from mainline:
index f2b3589c64e40bd8b3aed69733ee2ec859d5db3d..a70e9941a04016f9b8f0c2c69dad9f74988c2aca 100644 (file)
@@ -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 (file)
index 0000000..e812925
--- /dev/null
@@ -0,0 +1,9 @@
+enum Enum1 { None };
+
+namespace Test {
+   enum Enum2 { None };
+}
+
+namespace a {
+   enum { a } ;
+};