Patchwork C++ PATCH for c++/47277 (ICE on ill-formed enum dtor)

login
register
mail settings
Submitter Jason Merrill
Date May 28, 2011, 9:56 p.m.
Message ID <4DE16F95.9010903@redhat.com>
Download mbox | patch
Permalink /patch/97824/
State New
Headers show

Comments

Jason Merrill - May 28, 2011, 9:56 p.m.
As Paolo pointed out, our error message in this case could still be 
improved; this patch commits us to the pseudo-destructor interpretation 
if it's the only possible answer, so we get a better message about the 
use of an undeclared name.

Tested x86_64-pc-linux-gnu, applying to trunk.
Paolo Carlini - May 28, 2011, 10:59 p.m.
On 05/28/2011 11:56 PM, Jason Merrill wrote:
> As Paolo pointed out, our error message in this case could still be 
> improved; this patch commits us to the pseudo-destructor 
> interpretation if it's the only possible answer, so we get a better 
> message about the use of an undeclared name.
Ah, great. Thanks!

Paolo.

Patch

commit 9ad36320078a289add9d1757428dd9b2e9725099
Author: Jason Merrill <jason@redhat.com>
Date:   Fri May 27 23:30:56 2011 -0400

    	PR c++/47277
    	* parser.c (cp_parser_pseudo_destructor_name): Commit to parse
    	after we see the ~.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index a16ba89..75ad3f8 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -5642,6 +5642,11 @@  cp_parser_pseudo_destructor_name (cp_parser* parser,
 
   /* Look for the `~'.  */
   cp_parser_require (parser, CPP_COMPL, RT_COMPL);
+
+  /* Once we see the ~, this has to be a pseudo-destructor.  */
+  if (!processing_template_decl && !cp_parser_error_occurred (parser))
+    cp_parser_commit_to_tentative_parse (parser);
+
   /* Look for the type-name again.  We are not responsible for
      checking that it matches the first type-name.  */
   *type = cp_parser_nonclass_name (parser);
diff --git a/gcc/testsuite/g++.dg/cpp0x/enum18.C b/gcc/testsuite/g++.dg/cpp0x/enum18.C
index 5575ca6..306ed82 100644
--- a/gcc/testsuite/g++.dg/cpp0x/enum18.C
+++ b/gcc/testsuite/g++.dg/cpp0x/enum18.C
@@ -2,7 +2,7 @@ 
 // { dg-options -std=c++0x }
 
 int main(void) {
-           enum e {};
-           e ev;
-           ev.e::~e_u();	// { dg-error "" }
+  enum e {};
+  e ev;
+  ev.e::~e_u();	// { dg-error "e_u. has not been declared" }
 }