Commit de4317cc by Paolo Carlini Committed by Paolo Carlini

re PR c++/10207 (Empty structure initialization fails under C++ (but works under C))

/cp
2013-05-20  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/10207
	* parser.c (cp_parser_postfix_expression): Use cp_parser_braced_list
	instead of cp_parser_initializer_list for compound-literals.

/testsuite
2013-05-20  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/10207
	* g++.dg/ext/complit13.C: New.

From-SVN: r199096
parent 5657d966
2013-05-20 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/10207
* parser.c (cp_parser_postfix_expression): Use cp_parser_braced_list
instead of cp_parser_initializer_list for compound-literals.
2013-05-20 Marc Glisse <marc.glisse@inria.fr>
PR c++/57175
......
......@@ -5719,7 +5719,7 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
if (cp_parser_allow_gnu_extensions_p (parser)
&& cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
{
vec<constructor_elt, va_gc> *initializer_list = NULL;
tree initializer = NULL_TREE;
bool saved_in_type_id_in_expr_p;
cp_parser_parse_tentatively (parser);
......@@ -5732,21 +5732,19 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p;
/* Look for the `)'. */
cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
/* Look for the `{'. */
cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE);
/* If things aren't going well, there's no need to
keep going. */
if (!cp_parser_error_occurred (parser))
{
bool non_constant_p;
/* Parse the initializer-list. */
initializer_list
= cp_parser_initializer_list (parser, &non_constant_p);
/* Allow a trailing `,'. */
if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
cp_lexer_consume_token (parser->lexer);
/* Look for the final `}'. */
cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE);
if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE))
{
bool non_constant_p;
/* Parse the brace-enclosed initializer list. */
initializer = cp_parser_braced_list (parser,
&non_constant_p);
}
else
cp_parser_simulate_error (parser);
}
/* If that worked, we're definitely looking at a
compound-literal expression. */
......@@ -5754,7 +5752,8 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
{
/* Warn the user that a compound literal is not
allowed in standard C++. */
pedwarn (input_location, OPT_Wpedantic, "ISO C++ forbids compound-literals");
pedwarn (input_location, OPT_Wpedantic,
"ISO C++ forbids compound-literals");
/* For simplicity, we disallow compound literals in
constant-expressions. We could
allow compound literals of integer type, whose
......@@ -5772,10 +5771,8 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
}
/* Form the representation of the compound-literal. */
postfix_expression
= (finish_compound_literal
(type, build_constructor (init_list_type_node,
initializer_list),
tf_warning_or_error));
= finish_compound_literal (type, initializer,
tf_warning_or_error);
break;
}
}
......
2013-05-20 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/10207
* g++.dg/ext/complit13.C: New.
2013-05-20 Marc Glisse <marc.glisse@inria.fr>
PR c++/57175
......
// PR c++/10207
// { dg-options "" }
typedef struct { } EmptyStruct;
typedef struct { EmptyStruct Empty; } DemoStruct;
void Func()
{
DemoStruct Demo;
Demo.Empty = (EmptyStruct) {};
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment