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++/37647: ICE with invalid use of constructor


Hi Mark,

The problem is that DECL_CONSTRUCTOR is set for "void A();", which
implies that we call 'grok_ctor_properties' itself calling 'copy_fn_p',
that asserts that the passed declaration "has" DECL_FUNCTION_MEMBER_P,
which is obviously not the case here.

Is there any way that we can avoid even getting the idea that this is an sfk_constructor? Your patch seems like it's a bit later than we'd like; we're concluding that the function is sfk_constructor and then backing out when we notice that ctype is NULL. Can we just avoid concluding this is a constructor at all?
The attached patch does the check earlier and reports an error when
encountering a constructor or a destructor in a non-class scope.

I've successfully tested it on x86_64-apple-darwin-9. Is it better?
OK for 4.3 and for the mainline?

Thanks,
Simon

2008-10-24  Simon Martin  <simartin@users.sourceforge.net>

	PR c++/37647
	* decl.c (grokdeclarator): Reject [con|de]stuctors in a non-class
	scope.



Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 141326)
+++ gcc/cp/decl.c	(working copy)
@@ -9252,6 +9252,14 @@ grokdeclarator (const cp_declarator *dec
 		error ("virtual non-class function %qs", name);
 		virtualp = 0;
 	      }
+	    else if (sfk == sfk_constructor
+		     || sfk == sfk_destructor)
+	      {
+		error (funcdef_flag
+		       ? "%qs defined in a non-class scope"
+		       : "%qs declared in a non-class scope", name);
+		sfk = sfk_none;
+	      }
 	  }
 	else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2
 		 && !NEW_DELETE_OPNAME_P (original_name))



2008-10-24  Simon Martin  <simartin@users.sourceforge.net>

	PR c++/37647
	* g++.dg/parse/ctor9.C: New test.



/* PR c++/37647 */
/* { dg-do "compile" } */

struct A
{
  A() { void A(); } /* { dg-error "return type specification for constructor invalid|non-class scope" } */
};




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