[C++ PATCH] Fix ICE during C++11 lambda error recovery (PR c++/77791)

Jakub Jelinek jakub@redhat.com
Mon Oct 3 17:32:00 GMT 2016


Hi!

In param_list some entries could be error_mark_node, we should just ignore
those.  ALso, this patch optimizes by testing cxx_dialect < cxx14 just once.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-10-03  Jakub Jelinek  <jakub@redhat.com>

	PR c++/77791
	* parser.c (cp_parser_lambda_declarator_opt): Only pedwarn
	for C++11 on decls in the param_list.  Test cxx_dialect < cxx14 before
	the loop just once.

	* g++.dg/cpp0x/lambda/lambda-77791.C: New test.

--- gcc/cp/parser.c.jj	2016-09-27 21:09:59.000000000 +0200
+++ gcc/cp/parser.c	2016-10-03 15:00:31.759317804 +0200
@@ -10114,10 +10114,11 @@ cp_parser_lambda_declarator_opt (cp_pars
 
       /* Default arguments shall not be specified in the
 	 parameter-declaration-clause of a lambda-declarator.  */
-      for (tree t = param_list; t; t = TREE_CHAIN (t))
-	if (TREE_PURPOSE (t) && cxx_dialect < cxx14)
-	  pedwarn (DECL_SOURCE_LOCATION (TREE_VALUE (t)), OPT_Wpedantic,
-		   "default argument specified for lambda parameter");
+      if (cxx_dialect < cxx14)
+	for (tree t = param_list; t; t = TREE_CHAIN (t))
+	  if (TREE_PURPOSE (t) && DECL_P (TREE_VALUE (t)))
+	    pedwarn (DECL_SOURCE_LOCATION (TREE_VALUE (t)), OPT_Wpedantic,
+		     "default argument specified for lambda parameter");
 
       cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
 
--- gcc/testsuite/g++.dg/cpp0x/lambda/lambda-77791.C.jj	2016-10-03 15:01:21.831694292 +0200
+++ gcc/testsuite/g++.dg/cpp0x/lambda/lambda-77791.C	2016-10-03 14:58:22.000000000 +0200
@@ -0,0 +1,4 @@
+// PR c++/77791
+// { dg-do compile { target c++11 } }
+
+auto a = [] (int i, int i = 0) {};	// { dg-error "redefinition of" }

	Jakub



More information about the Gcc-patches mailing list