Now that we allow unexpanded packs in a lambda, since they can be part of the pattern of a pack expansion, we need to look at the argument types when we scan the full-expression later.
But fixing this added an unexpected error to the test for 81060, where we weren't properly diagnosing the unexpanded pack. Fixing that makes the unexpected error go away. I also noticed that the diagnostic location for the unexpanded pack in the lambda was the trailing semicolon, which is suboptimal. This turned out to be because EXPR_LOC_OR_LOC doesn't consider LAMBDA_EXPR_LOCATION, because LAMBDA_EXPR is tcc_exceptional, not EXPR_P. So I'm introducing cp_expr_loc_or_loc that handles LAMBDA_EXPR as well. I'm also changing the location of a LAMBDA_EXPR to be its full range, rather than just the first [. Tested x86_64-pc-linux-gnu, applying to trunk. First two patches also applying to 8.
commit d9959931944e05e8d4d7db5a0f617d5a47ee2f1a Author: Jason Merrill <ja...@redhat.com> Date: Mon Jun 18 16:03:32 2018 -0400 PR c++/86200 - ICE with unexpanded pack in lambda parameter. * pt.c (find_parameter_packs_r) [LAMBDA_EXPR]: Also look into the function type. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 5af0f9afefc..b783b5e1436 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -3839,8 +3839,10 @@ find_parameter_packs_r (tree *tp, int *walk_subtrees, void* data) cap; cap = TREE_CHAIN (cap)) cp_walk_tree (&TREE_VALUE (cap), &find_parameter_packs_r, ppd, ppd->visited); - /* Since we defer implicit capture, look in the body as well. */ + /* Since we defer implicit capture, look in the parms and body. */ tree fn = lambda_function (t); + cp_walk_tree (&TREE_TYPE (fn), &find_parameter_packs_r, ppd, + ppd->visited); cp_walk_tree (&DECL_SAVED_TREE (fn), &find_parameter_packs_r, ppd, ppd->visited); *walk_subtrees = 0; diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-variadic7.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-variadic7.C new file mode 100644 index 00000000000..c5355b0a8d8 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-variadic7.C @@ -0,0 +1,14 @@ +// PR c++/86200 +// { dg-do compile { target c++11 } } + +template<typename ... Args> +static void foo() +{ + [](Args, int x) { + x; + }; // { dg-error "packs not expanded" } +} +int main() +{ + foo(); +}