My change to accept C99 array-designators in C++ broke use of lambdas in an initializer-list, since both start with [. Fixed by parsing the array-designator tentatively.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit fc9080728a450c22b6f70c133e9d12835733195f
Author: Jason Merrill <ja...@redhat.com>
Date:   Mon Nov 7 17:23:46 2011 -0500

    	PR c++/50863
    	* parser.c (cp_parser_initializer_list): Parse C99
    	array designators tentatively.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index fa0117e..697be80 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -17580,10 +17580,13 @@ cp_parser_initializer_list (cp_parser* parser, bool* non_constant_p)
 	       && !c_dialect_objc ()
 	       && cp_lexer_next_token_is (parser->lexer, CPP_OPEN_SQUARE))
 	{
+	  /* 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);
 	  cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE);
 	  cp_parser_require (parser, CPP_EQ, RT_EQ);
+	  cp_parser_parse_definitely (parser);
 	}
       else
 	designator = NULL_TREE;
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-initlist1.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-initlist1.C
new file mode 100644
index 0000000..078ebae
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-initlist1.C
@@ -0,0 +1,12 @@
+// PR c++/50863
+// { dg-options -std=gnu++0x }
+
+struct T {
+  template<typename F>
+  T(F) { }
+};
+
+int main()
+{
+  T t{ []{ } };
+}

Reply via email to