Patchwork C++ PATCH for c++/47450 (defining class in new-expression)

login
register
mail settings
Submitter Jason Merrill
Date Jan. 6, 2012, 11:16 p.m.
Message ID <4F0780B1.6050302@redhat.com>
Download mbox | patch
Permalink /patch/134713/
State New
Headers show

Comments

Jason Merrill - Jan. 6, 2012, 11:16 p.m.
DR 686 clarified that it is ill-formed to define a class in the 
(type-id) of a new-expression as well as in a new-type-id.  This patch 
implements that, so we now reject the testcase.

Tested x86_64-pc-linux-gnu, applying to trunk.

Patch

commit f9a4c24ed3c76e4777414733d3c7de43c6642286
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Jan 6 17:59:50 2012 -0500

    	DR 686
    	PR c++/47450
    	* parser.c (cp_parser_new_expression): Set
    	type_definition_forbidden_message.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 0ae55a2..9be68d0 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -6668,10 +6668,17 @@  cp_parser_new_expression (cp_parser* parser)
   if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
     {
       cp_token *token;
+      const char *saved_message = parser->type_definition_forbidden_message;
+
       /* Consume the `('.  */
       cp_lexer_consume_token (parser->lexer);
+
       /* Parse the type-id.  */
+      parser->type_definition_forbidden_message
+	= G_("types may not be defined in a new-expression");
       type = cp_parser_type_id (parser);
+      parser->type_definition_forbidden_message = saved_message;
+
       /* Look for the closing `)'.  */
       cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
       token = cp_lexer_peek_token (parser->lexer);
diff --git a/gcc/testsuite/g++.dg/parse/new5.C b/gcc/testsuite/g++.dg/parse/new5.C
new file mode 100644
index 0000000..83937c6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/new5.C
@@ -0,0 +1,4 @@ 
+// PR c++/47450
+
+struct A { };
+A* ap = new(struct: A { });	// { dg-error "types may not be defined" }