summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2012-12-06 14:45:11 +0000
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2012-12-06 14:45:11 +0000
commita4be392bb35d0bf193f95121f76febbfef2999e2 (patch)
tree0c64c0a410f08e53dfe221b0eb67b889bc38d035
parent1a8a3492ad2746da195565a50147c57b45e79cd0 (diff)
downloadgcc-a4be392bb35d0bf193f95121f76febbfef2999e2.tar.gz
PR c++/54947
* parser.c (cp_parser_initializer_list): Don't require an expression in [] to be constant until we know it's a C99 designator. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@194256 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/parser.c5
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/lambda/lambda-initlist2.C27
3 files changed, 36 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 1a1f459f52f..96a88b92b19 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,10 @@
2012-12-06 Jason Merrill <jason@redhat.com>
+ PR c++/54947
+ * parser.c (cp_parser_initializer_list): Don't require an
+ expression in [] to be constant until we know it's a C99
+ designator.
+
PR c++/55015
PR c++/53821
* semantics.c (maybe_add_lambda_conv_op): Revert earlier change.
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 190b8d94113..a010f1fb305 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -17923,11 +17923,14 @@ cp_parser_initializer_list (cp_parser* parser, bool* non_constant_p)
/* In C++11, [ could start a lambda-introducer. */
cp_parser_parse_tentatively (parser);
cp_lexer_consume_token (parser->lexer);
- designator = cp_parser_constant_expression (parser, false, NULL);
+ bool non_const = false;
+ designator = cp_parser_constant_expression (parser, true, &non_const);
cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
cp_parser_require (parser, CPP_EQ, RT_EQ);
if (!cp_parser_parse_definitely (parser))
designator = NULL_TREE;
+ else if (non_const)
+ require_potential_rvalue_constant_expression (designator);
}
else
designator = NULL_TREE;
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-initlist2.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-initlist2.C
new file mode 100644
index 00000000000..daaa33938ad
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-initlist2.C
@@ -0,0 +1,27 @@
+// PR c++/54947
+// { dg-options -std=gnu++11 }
+
+struct X
+{
+ template<typename L>
+ X(L)
+ { }
+};
+
+template<typename A>
+ void
+ test()
+ {
+ int i = 0;
+
+ A a_ok_1( [=] { return i; } ); // OK
+ A a_ok_2( [i] { return i; } ); // OK
+
+ A a_err_1{ [i] { return i; } }; // error
+ A a_err_2{ [=] { return i; } }; // error
+ }
+
+int main()
+{
+ test<X>();
+}