https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61636
Takatoshi Kondo <redboltz at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |redboltz at gmail dot com --- Comment #17 from Takatoshi Kondo <redboltz at gmail dot com> --- x.g([]{}) made the following compile error only if it is called *after* calling f(x) without this->. It seems that a side effect of the problem. If I add this-> to f(x), all errors are disappeared. clang++ doesn't make a compile error. Error message -------------------- ccc_this2.cpp:9:10: note: no known conversion for argument 1 from ‘X::defer_f()::<lambda(auto:1)> [with auto:1 = X]::<lambda()>’ to ‘std::function<void()>’ gcc_this2.cpp:7:10: error: ‘void X::f(T) [with T = X::defer_f()::<lambda(auto:1)> [with auto:1 = X]::<lambda()>]’, declared using local type ‘X::defer_f()::<lambda(auto:1)> [with auto:1 = X]::<lambda()>’, is used but never defined [-fpermissive] void f(T) {} Code ----------------------------- #include <functional> struct X { // function template template <typename T> void f(T) {} // function that has std::function as a parameter void g(std::function<void()> = std::function<void()>()) {} // function (non template) void h() {} auto defer_f() { return [&] (auto x) { x.g([]{}); // Compile passed calling before f(x) f(x); // Compile error *1 (without this->) x.f([]{}); // Compile passed x.h(); // Compile passed x.g(); // Compile passed x.g([]{}); // Compile error (maybe side effect of *1) }; } }; int main() { X x; x.defer_f()(x); } Tested compiler -------------- gcc -v Using built-in specs. COLLECT_GCC=/usr/bin/gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: /build/gcc-multilib/src/gcc-5-20160209/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib --disable-werror --enable-checking=release Thread model: posix gcc version 5.3.0 (GCC) clang++ -v clang version 3.7.1 (tags/RELEASE_371/final) Target: x86_64-unknown-linux-gnu Thread model: posix Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-unknown-linux-gnu/5.3.0 Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/5.3.0 Found candidate GCC installation: /usr/lib/gcc/x86_64-unknown-linux-gnu/5.3.0 Found candidate GCC installation: /usr/lib64/gcc/x86_64-unknown-linux-gnu/5.3.0 Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/5.3.0 Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Selected multilib: .;@m64