public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Simon Martin <simartin@users.sourceforge.net>
To: Mark Mitchell <mark@codesourcery.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Fix PR c++/37647: ICE with invalid use of constructor
Date: Fri, 24 Oct 2008 21:42:00 -0000	[thread overview]
Message-ID: <49022260.8070307@users.sourceforge.net> (raw)
In-Reply-To: <48F26C19.6080803@codesourcery.com>

[-- 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" } */
};




      reply	other threads:[~2008-10-24 19:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-03  4:46 Simon Martin
2008-10-13  3:24 ` Mark Mitchell
2008-10-24 21:42   ` Simon Martin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49022260.8070307@users.sourceforge.net \
    --to=simartin@users.sourceforge.net \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=mark@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).