aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2013-05-20 09:41:42 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2013-05-20 09:41:42 +0000
commitde4317cce2a72cc333afdeb11e19786eb25cbf33 (patch)
tree03d5af74c833b41d567293dc88c5da738e5990a6 /gcc
parent5657d9661696f32b6bab45f511e67fa31b7aebc3 (diff)
downloadgcc-de4317cce2a72cc333afdeb11e19786eb25cbf33.zip
gcc-de4317cce2a72cc333afdeb11e19786eb25cbf33.tar.gz
gcc-de4317cce2a72cc333afdeb11e19786eb25cbf33.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/parser.c31
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/ext/complit13.C11
4 files changed, 36 insertions, 17 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 73b8deb..dd53e69 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+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
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 022886e..91e6615 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -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;
}
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 5a113d7..dfde009 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+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
diff --git a/gcc/testsuite/g++.dg/ext/complit13.C b/gcc/testsuite/g++.dg/ext/complit13.C
new file mode 100644
index 0000000..c12678b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/complit13.C
@@ -0,0 +1,11 @@
+// PR c++/10207
+// { dg-options "" }
+
+typedef struct { } EmptyStruct;
+typedef struct { EmptyStruct Empty; } DemoStruct;
+
+void Func()
+{
+ DemoStruct Demo;
+ Demo.Empty = (EmptyStruct) {};
+}