The code below has a lambda that captures the outer params t, for forwarding matter, decltype on t has to be used. ``` auto const pack = [](auto&&... t) { return [&](auto&& f)->decltype(auto) { return f(static_cast<decltype(t)>(t)...); }; }; int main(int argc, char** argv) { pack(1)([](int){}); return 0; } ``` It works with clang 3.5, but g++ 4.9.0 complains: error: 't' was not declared in this scope The same also applies to `sizeof` or that kind of compile-time thing.
This problem still happens on 4.9.1. For example, this example works: int main(int argc, char **argv) { int a{5}; float z(0.5); [&a](float z_) -> void { decltype(a) b = a; }(z); return 0; } But this basic modification fails to compile (g++-4.9.1 -std=gnu++14): int main(int argc, char **argv) { int a{5}; float z(0.5); [&a](auto z_) -> void { decltype(a) b = a; }(z); return 0; }
(In reply to Alexander Dubov from comment #1) > But this basic modification fails to compile (g++-4.9.1 -std=gnu++14): > > int main(int argc, char **argv) > { > int a{5}; > float z(0.5); > [&a](auto z_) -> void { > decltype(a) b = a; > }(z); > return 0; > } That seems to be a different issue, and is fixed on trunk.
Actually the original problem is fixed on trunk too (but gives a different error now), so maybe it is the same and can be reduced to: int main() { int a{5}; [&a](auto z) -> void { decltype(a) b = a; }(1); } l.cc: In instantiation of ‘main()::<lambda(auto:1)> [with auto:1 = int]’: l.cc:6:6: required from here l.cc:5:17: error: ‘a’ was not declared in this scope decltype(a) b = a; ^ The error goes away if the lambda doesn't have a trailing-return-type, or if it's not a generic lambda. Jason, is it worth fixing this on the branch? It only affects C++14 mode.
Fixed. *** This bug has been marked as a duplicate of bug 63628 ***