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]

PATCH for bogus namespace usage



Here's a patch which causes g++ to (correctly) flag errors on some
bogus namespace constructs.

-- 
Mark Mitchell 			mark@markmitchell.com
Mark Mitchell Consulting	http://www.markmitchell.com

Index: cp/decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.176
diff -c -p -r1.176 decl.c
*** decl.c	1998/08/06 16:56:38	1.176
--- decl.c	1998/08/12 20:44:50
*************** grokdeclarator (declarator, declspecs, d
*** 10125,10131 ****
  
      if (decl_context == PARM)
        {
! 	if (ctype)
  	  error ("cannot use `::' in parameter declaration");
  
  	/* A parameter declared as an array of T is really a pointer to T.
--- 10125,10131 ----
  
      if (decl_context == PARM)
        {
! 	if (ctype || in_namespace)
  	  error ("cannot use `::' in parameter declaration");
  
  	/* A parameter declared as an array of T is really a pointer to T.
*************** grokdeclarator (declarator, declspecs, d
*** 10177,10182 ****
--- 10177,10188 ----
  	  {
  	    /* Happens when declaring arrays of sizes which
  	       are error_mark_node, for example.  */
+ 	    decl = NULL_TREE;
+ 	  }
+ 	else if (in_namespace)
+ 	  {
+ 	    /* Something like struct S { int N::j; };  */
+ 	    cp_error ("invalid use of `::'");
  	    decl = NULL_TREE;
  	  }
  	else if (TREE_CODE (type) == FUNCTION_TYPE)
Index: testsuite/g++.old-deja/g++.ns/bogus1.C
===================================================================
RCS file: bogus1.C
diff -N bogus1.C
*** /dev/null	Mon Dec 31 20:00:00 1979
--- bogus1.C	Wed Aug 12 13:44:50 1998
***************
*** 0 ****
--- 1,10 ----
+ // Build don't link:
+ 
+ namespace N {}
+ 
+ void f(int N::k); // ERROR - cannot use `::' in parameter declaration
+ 
+ class Foo
+ {
+   int N::j; // ERROR - invalid use of `::'
+ };


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