http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52183
Bug #: 52183 Summary: Redeclaration of __this in lambda inside template member function when calling static class function Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: stefan.bo...@gmx.de When compiling #include <functional> struct A { template<class T> void f (T x) { std::function<void ()> aux; aux = [&] () -> void{ s(); aux (); }; } static void s () { } }; template void A::f<int> (int); code is rejected by the compiler by the error message below. Expected behavior is compilation without an error. stefan@bluebox:/tmp$ g++-svn -std=c++0x -v --save-temps foo.cpp Using built-in specs. COLLECT_GCC=g++-svn COLLECT_LTO_WRAPPER=/home/stefan/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../trunk/configure --enable-languages=c,c++ --prefix=/home/stefan --program-suffix=-svn --disable-multilib Thread model: posix gcc version 4.7.0 20120126 (experimental) (GCC) COLLECT_GCC_OPTIONS='-std=c++11' '-v' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /home/stefan/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/cc1plus -E -quiet -v -D_GNU_SOURCE foo.cpp -mtune=generic -march=x86-64 -std=c++11 -fpch-preprocess -o foo.ii ignoring nonexistent directory "/home/stefan/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../x86_64-unknown-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /home/stefan/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0 /home/stefan/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/x86_64-unknown-linux-gnu /home/stefan/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/backward /home/stefan/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/include /usr/local/include /home/stefan/include /home/stefan/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/include-fixed /usr/include End of search list. COLLECT_GCC_OPTIONS='-std=c++11' '-v' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /home/stefan/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/cc1plus -fpreprocessed foo.ii -quiet -dumpbase foo.cpp -mtune=generic -march=x86-64 -auxbase foo -std=c++11 -version -o foo.s GNU C++ (GCC) version 4.7.0 20120126 (experimental) (x86_64-unknown-linux-gnu) compiled by GNU C version 4.7.0 20120126 (experimental), GMP version 5.0.1, MPFR version 3.0.1-p3, MPC version 0.9 GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096 GNU C++ (GCC) version 4.7.0 20120126 (experimental) (x86_64-unknown-linux-gnu) compiled by GNU C version 4.7.0 20120126 (experimental), GMP version 5.0.1, MPFR version 3.0.1-p3, MPC version 0.9 GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096 Compiler executable checksum: 587bcf77b9db77a91e3cc4b379a04aff foo.cpp: In instantiation of ‘A::f(T) [with T = int]::<lambda()>’: foo.cpp:10:7: required from ‘struct A::f(T) [with T = int]::<lambda()>’ foo.cpp:8:5: required from ‘void A::f(T) [with T = int]’ foo.cpp:17:29: required from here foo.cpp:9:9: error: redeclaration of ‘A* const A::f(T) [with T = int]::<lambda()>::__this’ foo.cpp:9:9: note: previous declaration ‘A* const A::f(T) [with T = int]::<lambda()>::__this’ foo.cpp:9:9: error: redeclaration of ‘A* const this’ foo.cpp:9:9: error: ‘A* const this’ previously declared here In file included from foo.cpp:1:0: /home/stefan/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/functional:2172:2: error: ‘typename std::enable_if<(! std::is_integral<_Functor>::value), std::function<_Res(_ArgTypes ...)>&>::type std::function<_Res(_ArgTypes ...)>::operator=(_Functor&&) [with _Functor = A::f(T) [with T = int]::<lambda()>; _Res = void; _ArgTypes = {}; typename std::enable_if<(! std::is_integral<_Functor>::value), std::function<_Res(_ArgTypes ...)>&>::type = std::function<void()>&]’, declared using local type ‘A::f(T) [with T = int]::<lambda()>’, is used but never defined [-fpermissive]