1 // PR c++/77585 2 // { dg-do run { target c++14 } } 3 4 // Confusion about this capture when instantiating generic lambda's 5 // function operator 6 Eat(F && f)7template <typename F> int Eat (F &&f) { return f (1); } 8 9 struct Foo { 10 int x = 1; ShareFoo11 int Share () { return x++; } 12 int Frob (int); 13 }; 14 Frob(int r)15int Foo::Frob (int r) 16 { 17 auto lam = [&](auto) { return Share (); }; 18 r += Eat (lam); 19 20 auto lam0 = [&](auto) { 21 auto lam1 = [&](auto) { return Share (); }; 22 return Eat (lam1); }; 23 r += Eat (lam0); 24 25 return r; 26 } 27 Frob(int r)28int Frob (int r) 29 { 30 auto lam = [&](auto) { return 1; }; 31 r += Eat (lam); 32 return r; 33 } 34 35 main()36int main () 37 { 38 Foo f; 39 40 return Frob (f.Frob (0)) == 4 ? 0 : 1; 41 } 42