.. Ah! I think I have a much better tentative fix, which, as it happens, also leads to a diagnostics quite close to that produced by the EDG front-end.

The idea is checking for the offending case and not handling it in any special way besides turning need_new = 1, as if for a normal new declaration: actually in this case it conflicts with the existing one from the namespace alias declaration, and leads to a guaranteed error a bit later. Patch passes testing.

Thanks,
Paolo.

///////////////////////
Index: testsuite/g++.dg/parse/namespace-alias-1.C
===================================================================
--- testsuite/g++.dg/parse/namespace-alias-1.C  (revision 0)
+++ testsuite/g++.dg/parse/namespace-alias-1.C  (revision 0)
@@ -0,0 +1,7 @@
+// PR c++/26155
+
+namespace N
+{
+  namespace M = N;  // { dg-error "previous declaration" }
+  namespace M {}    // { dg-error "declaration of namespace" }
+}
Index: cp/name-lookup.c
===================================================================
--- cp/name-lookup.c    (revision 187991)
+++ cp/name-lookup.c    (working copy)
@@ -3544,12 +3544,20 @@ push_namespace (tree name)
       d = IDENTIFIER_NAMESPACE_VALUE (name);
       if (d != NULL_TREE && TREE_CODE (d) == NAMESPACE_DECL)
        {
+         tree dna = DECL_NAMESPACE_ALIAS (d);
          need_new = 0;
-         if (DECL_NAMESPACE_ALIAS (d))
+         if (dna)
            {
-             error ("namespace alias %qD not allowed here, assuming %qD",
-                    d, DECL_NAMESPACE_ALIAS (d));
-             d = DECL_NAMESPACE_ALIAS (d);
+             if (NAMESPACE_LEVEL (dna)->level_chain
+                 == current_binding_level)
+               {
+                 error ("namespace alias %qD not allowed here, "
+                        "assuming %qD", d, dna);
+                 d = dna;
+               }
+             else
+               /* We error out below.  */
+               need_new = 1;
            }
        }
     }

Reply via email to