public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix PR c++/37647: ICE with invalid use of constructor
@ 2008-10-03  4:46 Simon Martin
  2008-10-13  3:24 ` Mark Mitchell
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Martin @ 2008-10-03  4:46 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 770 bytes --]

Hi all.

The following invalid snippet triggers an ICE with 4.3 and 4.4

=== cut here ===
struct A
{
     A() { void A(); }
};
=== cut here ===


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.

This regression has been introduced by my fix for PR c++/29077 that is
not correct since it sets DECL_{CONS,DES}TRUCTOR regardless of 'ctype',
while it should do it only when 'ctype' is not NULL_TREE. The attached
patch fixes this.

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

Thanks in advance,
Simon

:ADDPATCH c++:



[-- Attachment #2: CL_37647 --]
[-- Type: text/plain, Size: 141 bytes --]

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

	PR c++/37647
	* decl.c (grokfndecl): Don't honour SFK in a non class context.



[-- Attachment #3: pr37647.patch --]
[-- Type: text/plain, Size: 545 bytes --]

Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 140838)
+++ gcc/cp/decl.c	(working copy)
@@ -6531,10 +6531,10 @@ grokfndecl (tree ctype,
     {
     case sfk_constructor:
     case sfk_copy_constructor:
-      DECL_CONSTRUCTOR_P (decl) = 1;
+      DECL_CONSTRUCTOR_P (decl) = (ctype != NULL_TREE);
       break;
     case sfk_destructor:
-      DECL_DESTRUCTOR_P (decl) = 1;
+      DECL_DESTRUCTOR_P (decl) =  (ctype != NULL_TREE);
       break;
     default:
       break;



[-- Attachment #4: CL_37647_testsuite --]
[-- Type: text/plain, Size: 111 bytes --]

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

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



[-- Attachment #5: ctor9.C --]
[-- Type: text/plain, Size: 153 bytes --]

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

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix PR c++/37647: ICE with invalid use of constructor
  2008-10-03  4:46 [PATCH] Fix PR c++/37647: ICE with invalid use of constructor Simon Martin
@ 2008-10-13  3:24 ` Mark Mitchell
  2008-10-24 21:42   ` Simon Martin
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Mitchell @ 2008-10-13  3:24 UTC (permalink / raw)
  To: Simon Martin; +Cc: gcc-patches

Simon Martin wrote:

> 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?

Thanks,

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix PR c++/37647: ICE with invalid use of constructor
  2008-10-13  3:24 ` Mark Mitchell
@ 2008-10-24 21:42   ` Simon Martin
  0 siblings, 0 replies; 3+ messages in thread
From: Simon Martin @ 2008-10-24 21:42 UTC (permalink / raw)
  To: Mark Mitchell; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 850 bytes --]

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


[-- Attachment #2: CL_37647 --]
[-- Type: text/plain, Size: 152 bytes --]

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

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




[-- Attachment #3: pr37647_2.patch --]
[-- Type: text/plain, Size: 651 bytes --]

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))




[-- Attachment #4: CL_37647_testsuite --]
[-- Type: text/plain, Size: 112 bytes --]

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

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




[-- Attachment #5: ctor9.C --]
[-- Type: text/plain, Size: 170 bytes --]

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

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




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-10-24 19:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-03  4:46 [PATCH] Fix PR c++/37647: ICE with invalid use of constructor Simon Martin
2008-10-13  3:24 ` Mark Mitchell
2008-10-24 21:42   ` Simon Martin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).