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]

C++ PATCH: PR 28056


This patch fixes PR c++/28056, an accepts-invalid regression on: 

  enum A {};
  void foo() { A::bar(); }

Volker (quite reasonably) thought the bug was that we were treating
"A::bar" as a valid qualified-name, but what we were really doing is
treating "::bar" as a valid function-name.  (In other words, we were
treating this code as a function-declarator for a global function
"bar" returning an "A".)

Tested on x86_64-unknown-linux-gnu, applied on the mainline and on the
4.1 branch.

--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

2006-08-25  Mark Mitchell  <mark@codesourcery.com>

	PR c++/28056
	* decl.c (grokdeclarator): Disallow declarations with qualified
	names in local scopes.

2006-08-25  Mark Mitchell  <mark@codesourcery.com>

	PR c++/28056
	* g++.dg/parse/local1.C: New test.
	* g++.dg/other/qual1.C: Tweak error marker.

Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 116277)
+++ gcc/cp/decl.c	(working copy)
@@ -6959,7 +6959,27 @@ grokdeclarator (const cp_declarator *dec
 	      break;
 	    if (qualifying_scope)
 	      {
-		if (TYPE_P (qualifying_scope))
+		if (at_function_scope_p ())
+		  {
+		    /* [dcl.meaning] 
+
+		       A declarator-id shall not be qualified except
+		       for ... 
+
+		       None of the cases are permitted in block
+		       scope.  */
+		    if (qualifying_scope == global_namespace)
+		      error ("invalid use of qualified-name %<::%D%>",
+			     decl);
+		    else if (TYPE_P (qualifying_scope))
+		      error ("invalid use of qualified-name %<%T::%D%>",
+			     qualifying_scope, decl);
+		    else 
+		      error ("invalid use of qualified-name %<%D::%D%>",
+			     qualifying_scope, decl);
+		    return error_mark_node;
+		  }
+		else if (TYPE_P (qualifying_scope))
 		  {
 		    ctype = qualifying_scope;
 		    if (innermost_code != cdk_function
Index: gcc/testsuite/g++.dg/other/qual1.C
===================================================================
--- gcc/testsuite/g++.dg/other/qual1.C	(revision 116277)
+++ gcc/testsuite/g++.dg/other/qual1.C	(working copy)
@@ -6,6 +6,6 @@ struct A
   int i;
   void foo()
   {
-    int A::i = i;  // { dg-error "extra qualification|not a static member" }
+    int A::i = i;  // { dg-error "qualified" }
   }
 };
Index: gcc/testsuite/g++.dg/parse/local1.C
===================================================================
--- gcc/testsuite/g++.dg/parse/local1.C	(revision 0)
+++ gcc/testsuite/g++.dg/parse/local1.C	(revision 0)
@@ -0,0 +1,18 @@
+// PR c++/28056
+
+void f1();
+
+namespace N {
+  void f2();
+}
+
+class C {
+  static void f3();
+};
+
+void foo() { 
+  void ::f1();  // { dg-error "qualified" }
+  void N::f2(); // { dg-error "qualified" }
+  void C::f3(); // { dg-error "qualified" }
+  void ::f4();  // { dg-error "qualified" }
+}


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