https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77523
Bug ID: 77523 Summary: rejects valid C++14 code with initialized lambda capture Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: su at cs dot ucdavis.edu Target Milestone: --- The code is accepted by both Clang and MSVC (it is derived from PR 77522's test). $ g++-trunk -v Using built-in specs. COLLECT_GCC=g++-trunk COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/7.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc-source-trunk/configure --enable-languages=c,c++,lto --prefix=/usr/local/gcc-trunk --disable-bootstrap Thread model: posix gcc version 7.0.0 20160907 (experimental) [trunk revision 240025] (GCC) $ $ clang++ -c -std=c++14 small.cpp $ $ g++-trunk -c -std=c++14 small.cpp small.cpp: In function ‘void f(T)’: small.cpp:3:18: error: cannot capture ‘f<>’ by reference auto g = [&a = f <>] () {}; ^~~~ small.cpp: In instantiation of ‘void f(T) [with T = int]’: small.cpp:8:7: required from here small.cpp:3:12: error: cannot bind non-const lvalue reference of type ‘void (*&)(int)’ to an rvalue of type ‘void (*)(int)’ auto g = [&a = f <>] () {}; ^ $ ----------------------------------------- template < class T = int > void f (T) { auto g = [&a = f <>] () {}; } int main () { f (0); return 0; }