diff mbox

[C++] PR 41769

Message ID 4DF2650A.70906@oracle.com
State New
Headers show

Commit Message

Paolo Carlini June 10, 2011, 6:40 p.m. UTC
Hi,

as it happens, a couple of years ago Johannes filed a PR quite similar 
to 29003 but for function parameters, and we have a similar issue for 
catch clauses too. Patch tested x86_64-linux.

Is it Ok?

Thanks,
Paolo.

/////////////////////
/cp
2011-06-10  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/29003
	* decl.c (grokdeclarator): Reject operator names in parameters.

/testsuite
2011-06-10  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/29003
	* g++.dg/parse/error39.C: New.

Comments

Jason Merrill June 10, 2011, 6:42 p.m. UTC | #1
OK.

Jason
diff mbox

Patch

Index: testsuite/g++.dg/parse/error39.C
===================================================================
--- testsuite/g++.dg/parse/error39.C	(revision 0)
+++ testsuite/g++.dg/parse/error39.C	(revision 0)
@@ -0,0 +1,14 @@ 
+// PR c++/41769
+
+void f(void operator+()); // { dg-error "declaration" }
+
+void g()
+{
+  try
+    {
+
+    }
+  catch(void operator+()) // { dg-error "declaration" }
+    {
+    }
+}
Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 174918)
+++ cp/decl.c	(working copy)
@@ -8441,11 +8441,18 @@  grokdeclarator (const cp_declarator *declarator,
       return error_mark_node;
     }
 
-  if (dname && IDENTIFIER_OPNAME_P (dname)
-      && declspecs->specs[(int)ds_typedef])
+  if (dname && IDENTIFIER_OPNAME_P (dname))
     {
-      error ("declaration of %qD as %<typedef%>", dname);
-      return error_mark_node;
+      if (declspecs->specs[(int)ds_typedef])
+	{
+	  error ("declaration of %qD as %<typedef%>", dname);
+	  return error_mark_node;
+	}
+      else if (decl_context == PARM || decl_context == CATCHPARM)
+	{
+	  error ("declaration of %qD as parameter", dname);
+	  return error_mark_node;
+	}
     }
 
   /* Anything declared one level down from the top level