If A<int> isn't instantiated by the time we build the capture proxy VAR_DECL, it gets no DECL_SIZE. So make sure it is.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit e979dc834d91e52c0c568f85c2b62ec67dac3cdc Author: Jason Merrill <ja...@redhat.com> Date: Mon Mar 12 01:01:14 2018 -0400 PR c++/84802 - ICE capturing uninstantiated class. * lambda.c (build_capture_proxy): Call complete_type. diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c index de064ffc85e..b3c75c84682 100644 --- a/gcc/cp/lambda.c +++ b/gcc/cp/lambda.c @@ -432,6 +432,8 @@ build_capture_proxy (tree member, tree init) object = convert (type, ptr); } + complete_type (type); + var = build_decl (input_location, VAR_DECL, name, type); SET_DECL_VALUE_EXPR (var, object); DECL_HAS_VALUE_EXPR_P (var) = 1; diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-ice9.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-ice9.C new file mode 100644 index 00000000000..a07acfff884 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-ice9.C @@ -0,0 +1,11 @@ +// PR c++/84802 +// { dg-do compile { target c++14 } } + +template <class T> struct A { }; + +void f (A<int>& ar) +{ + [](const auto& x) + { return [x]{}(); } + (ar); +}