This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Fix PR c++/23586: Bad diagnostic for invalid namespace-name


Hi Gaby,

On 29 Aug, Mark Mitchell wrote:
> Volker Reichelt wrote:
> 
>> 2005-08-26  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
>> 
>> 	* parser.c (cp_parser_namespace_name): Move diagnostic for
>>         invalid namespace-name to here from ...
>> 	* name-lookup.c (do_namespace_alias): ... here and ...
>> 	(do_using_directive): ... here.  Remove dead code.
> 
> OK.

here's the backport of the patch for the 3.4 branch. It's a straight
backport of the patch for mainline and the 4.0 branch (which Mark
approved).

Bootstrapped and regtested on i686-pc-linux-gnu.
Ok for the 3.4 branch?

Regards,
Volker


2005-08-31  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/23586
	* parser.c (cp_parser_namespace_name): Move diagnostic for
	invalid namespace-name to here from ...
	* name-lookup.c (do_namespace_alias): ... here and ...
	(do_using_directive): ... here.  Remove dead code.

===================================================================
--- gcc/gcc/cp/parser.c	28 Jul 2005 10:22:09 -0000	1.157.2.58
+++ gcc/gcc/cp/parser.c	30 Aug 2005 16:57:40 -0000
@@ -9532,6 +9532,9 @@ cp_parser_namespace_name (cp_parser* par
   if (namespace_decl == error_mark_node
       || TREE_CODE (namespace_decl) != NAMESPACE_DECL)
     {
+      if (!cp_parser_parsing_tentatively (parser)
+	  || cp_parser_committed_to_tentative_parse (parser))
+	error ("`%D' is not a namespace-name", identifier);
       cp_parser_error (parser, "expected namespace-name");
       namespace_decl = error_mark_node;
     }
===================================================================
--- gcc/gcc/cp/name-lookup.c	2 Mar 2005 19:57:07 -0000	1.34.2.22
+++ gcc/gcc/cp/name-lookup.c	30 Aug 2005 16:53:23 -0000
@@ -3199,12 +3199,10 @@ namespace_ancestor (tree ns1, tree ns2)
 void
 do_namespace_alias (tree alias, tree namespace)
 {
-  if (TREE_CODE (namespace) != NAMESPACE_DECL)
-    {
-      /* The parser did not find it, so it's not there.  */
-      error ("unknown namespace `%D'", namespace);
-      return;
-    }
+  if (namespace == error_mark_node)
+    return;
+
+  my_friendly_assert (TREE_CODE (namespace) == NAMESPACE_DECL, 20050830);
 
   namespace = ORIGINAL_NAMESPACE (namespace);
 
@@ -3345,26 +3343,15 @@ do_toplevel_using_decl (tree decl, tree 
 void
 do_using_directive (tree namespace)
 {
+  if (namespace == error_mark_node)
+    return;
+
+  my_friendly_assert (TREE_CODE (namespace) == NAMESPACE_DECL, 20050830);
+
   if (building_stmt_tree ())
     add_stmt (build_stmt (USING_STMT, namespace));
-  
-  /* using namespace A::B::C; */
-  if (TREE_CODE (namespace) == SCOPE_REF)
-      namespace = TREE_OPERAND (namespace, 1);
-  if (TREE_CODE (namespace) == IDENTIFIER_NODE)
-    {
-      /* Lookup in lexer did not find a namespace.  */
-      if (!processing_template_decl)
-	error ("namespace `%T' undeclared", namespace);
-      return;
-    }
-  if (TREE_CODE (namespace) != NAMESPACE_DECL)
-    {
-      if (!processing_template_decl)
-	error ("`%T' is not a namespace", namespace);
-      return;
-    }
   namespace = ORIGINAL_NAMESPACE (namespace);
+
   if (!toplevel_bindings_p ())
     push_using_directive (namespace);
   else
===================================================================



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]