http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59944
Bug ID: 59944
Summary: lambda in templated method body for method with
default template value and lambda parameter causes
error
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: balint at posteo dot de
Created attachment 31953
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31953&action=edit
compressed ii file
Take a class with a templated method, let the template parameter have a default
value and let the method have a std::function as only parameter with a lambda
as default value for the parameter. Now inside this function use another,
independent lambda, e.g. in the context of "remove_if". Then g++ in all tested
versions (4.8.1, 4.8.2, 4.9) throws several errors.
Please see for discussion, code sample and explanation:
http://stackoverflow.com/questions/21353349/c11-g-strangeness-using-defaulted-template-lambda-remove-if
Regarding the details you request for bug reports, here we go:
command line:
g++-4.9 -v -std=c++0x example3.cpp
(NOTE: example3.cpp contains the code shown in the stackoverflow link)
system info:
LinuxMint 16 (petra)
3.8.4 (Ubuntu 2013-12-05)
3.11.0-12-generic (#19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013)
gcc version:
GNU C++ (Ubuntu 20130917-1ubuntu1) version 4.9.0 20130917 (experimental) [trunk
revision 202647] (x86_64-linux-gnu)
compiled by GNU C version 4.9.0 20130917 (experimental) [trunk revision
202647], GMP version 5.1.2, MPFR version 3.1.1-p2, MPC version 1.0.1
gcc config options:
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
20130917-1ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-snapshot/README.Bugs
--enable-languages=c,ada,c++,java,go,fortran,objc,obj-c++
--prefix=/usr/lib/gcc-snapshot --enable-shared --enable-linker-build-id
--disable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin
--with-system-zlib --disable-browser-plugin --enable-java-awt=gtk
--enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-snap-amd64/jre
--enable-java-home
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-snap-amd64
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-snap-amd64
--with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic
--enable-checking=yes --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
ii-file:
see attachment
gcc complete verbose compiler output:
Using built-in specs.
COLLECT_GCC=g++-4.9
COLLECT_LTO_WRAPPER=/usr/lib/gcc-snapshot/libexec/gcc/x86_64-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
20130917-1ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-snapshot/README.Bugs
--enable-languages=c,ada,c++,java,go,fortran,objc,obj-c++
--prefix=/usr/lib/gcc-snapshot --enable-shared --enable-linker-build-id
--disable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin
--with-system-zlib --disable-browser-plugin --enable-java-awt=gtk
--enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-snap-amd64/jre
--enable-java-home
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-snap-amd64
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-snap-amd64
--with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic
--enable-checking=yes --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 4.9.0 20130917 (experimental) [trunk revision 202647] (Ubuntu
20130917-1ubuntu1)
COLLECT_GCC_OPTIONS='-v' '-std=c++11' '-shared-libgcc' '-mtune=generic'
'-march=x86-64'
/usr/lib/gcc-snapshot/libexec/gcc/x86_64-linux-gnu/4.9.0/cc1plus -quiet -v
-imultiarch x86_64-linux-gnu -D_GNU_SOURCE example3.cpp -quiet -dumpbase
example3.cpp -mtune=generic -march=x86-64 -auxbase example3 -std=c++11 -version
-o /tmp/ccYCvqsx.s
GNU C++ (Ubuntu 20130917-1ubuntu1) version 4.9.0 20130917 (experimental) [trunk
revision 202647] (x86_64-linux-gnu)
compiled by GNU C version 4.9.0 20130917 (experimental) [trunk revision
202647], GMP version 5.1.2, MPFR version 3.1.1-p2, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc-snapshot/lib/gcc/x86_64-linux-gnu/4.9.0/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc-snapshot/lib/gcc/x86_64-linux-gnu/4.9.0/../../../../include/c++/4.9.0
/usr/lib/gcc-snapshot/lib/gcc/x86_64-linux-gnu/4.9.0/../../../../include/c++/4.9.0/x86_64-linux-gnu
/usr/lib/gcc-snapshot/lib/gcc/x86_64-linux-gnu/4.9.0/../../../../include/c++/4.9.0/backward
/usr/lib/gcc-snapshot/lib/gcc/x86_64-linux-gnu/4.9.0/include
/usr/local/include
/usr/lib/gcc-snapshot/lib/gcc/x86_64-linux-gnu/4.9.0/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
GNU C++ (Ubuntu 20130917-1ubuntu1) version 4.9.0 20130917 (experimental) [trunk
revision 202647] (x86_64-linux-gnu)
compiled by GNU C version 4.9.0 20130917 (experimental) [trunk revision
202647], GMP version 5.1.2, MPFR version 3.1.1-p2, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: c251dd37365dbb1c49e0a7e336cbf236
example3.cpp: In member function 'bool Foo::Moo(std::function<bool()>) const':
example3.cpp:17:19: error: default argument for template parameter for class
enclosing 'Foo::Moo(std::function<bool()>) const::<lambda>'
[](char x){return true;}),
^
example3.cpp: In function 'int main(int, char**)':
example3.cpp:27:22: error: no matching function for call to 'Foo::Moo()'
return myFoo->Moo<>();
^
example3.cpp:27:22: note: candidate is:
example3.cpp:12:7: note: template<class T> bool Foo::Moo(std::function<bool()>)
const
bool Moo(std::function<bool()> f = [](){ return true; }) const
^
example3.cpp:12:7: note: template argument deduction/substitution failed:
example3.cpp:27:22: note: couldn't deduce template parameter 'T'
return myFoo->Moo<>();
^