]> gcc.gnu.org Git - gcc.git/commitdiff
re PR c++/26155 (ICE after error with namespace alias)
authorPaolo Carlini <paolo.carlini@oracle.com>
Fri, 1 Jun 2012 16:11:38 +0000 (16:11 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Fri, 1 Jun 2012 16:11:38 +0000 (16:11 +0000)
/cp
2012-06-01  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/26155
* name-lookup.c (push_namespace): When error recovery is
impossible just error out in duplicate_decls.

/testsuite
2012-06-01  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/26155
* g++.dg/parse/namespace-alias-1.C: New.

From-SVN: r188113

gcc/cp/ChangeLog
gcc/cp/name-lookup.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/namespace-alias-1.C [new file with mode: 0644]

index b1f073460ace5dfacc95332b7d1c87edcf47b7e8..95e698d72ae4967fef1fc798356690023c45b9bf 100644 (file)
@@ -1,3 +1,9 @@
+2012-06-01  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/26155
+       * name-lookup.c (push_namespace): When error recovery is
+       impossible just error out in duplicate_decls.
+
 2012-05-31  Steven Bosscher  <steven@gcc.gnu.org>
 
        * call.c: Do not include output.h.
index 6930502012bad02aa83dc54bc9d545e4cc8cc420..642f39f2628da6e91846f31ff2917a444fb4d0e2 100644 (file)
@@ -3518,8 +3518,8 @@ void
 push_namespace (tree name)
 {
   tree d = NULL_TREE;
-  int need_new = 1;
-  int implicit_use = 0;
+  bool need_new = true;
+  bool implicit_use = false;
   bool anon = !name;
 
   bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
@@ -3535,8 +3535,8 @@ push_namespace (tree name)
       d = IDENTIFIER_NAMESPACE_VALUE (name);
       if (d)
        /* Reopening anonymous namespace.  */
-       need_new = 0;
-      implicit_use = 1;
+       need_new = false;
+      implicit_use = true;
     }
   else
     {
@@ -3544,13 +3544,36 @@ push_namespace (tree name)
       d = IDENTIFIER_NAMESPACE_VALUE (name);
       if (d != NULL_TREE && TREE_CODE (d) == NAMESPACE_DECL)
        {
-         need_new = 0;
-         if (DECL_NAMESPACE_ALIAS (d))
-           {
-             error ("namespace alias %qD not allowed here, assuming %qD",
-                    d, DECL_NAMESPACE_ALIAS (d));
-             d = DECL_NAMESPACE_ALIAS (d);
+         tree dna = DECL_NAMESPACE_ALIAS (d);
+         if (dna)
+           {
+             /* We do some error recovery for, eg, the redeclaration
+                of M here:
+
+                namespace N {}
+                namespace M = N;
+                namespace M {}
+
+                However, in nasty cases like:
+
+                namespace N
+                {
+                  namespace M = N;
+                  namespace M {}
+                }
+
+                we just error out below, in duplicate_decls.  */
+             if (NAMESPACE_LEVEL (dna)->level_chain
+                 == current_binding_level)
+               {
+                 error ("namespace alias %qD not allowed here, "
+                        "assuming %qD", d, dna);
+                 d = dna;
+                 need_new = false;
+               }
            }
+         else
+           need_new = false;
        }
     }
 
index 56bc07071cade390c39f064eb95b60c0449bdca6..28b853f598127e827f79c17ccfe7194570d29301 100644 (file)
@@ -1,3 +1,8 @@
+2012-06-01  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/26155
+       * g++.dg/parse/namespace-alias-1.C: New.
+
 2012-06-01  Christian Bruel  <christian.bruel@st.com>
 
        * gcc.dg/spec-options.c: New test.
diff --git a/gcc/testsuite/g++.dg/parse/namespace-alias-1.C b/gcc/testsuite/g++.dg/parse/namespace-alias-1.C
new file mode 100644 (file)
index 0000000..627a95b
--- /dev/null
@@ -0,0 +1,7 @@
+// PR c++/26155
+
+namespace N
+{
+  namespace M = N;  // { dg-error "previous declaration" }
+  namespace M {}    // { dg-error "declaration of namespace" }
+}
This page took 0.090962 seconds and 5 git commands to generate.