http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57899
Bug ID: 57899 Summary: bind/function with data member: infinite recursion Product: gcc Version: 4.8.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jpr at essi dot fr The following program fails to compile with gcc-4.8.1 in C++11 mode: #include <cassert> #include <string> #include <map> #include <list> #include <algorithm> #include <functional> using namespace std; using namespace std::placeholders; int main() { map<string, int> table = {{"0123456789012345", 0}}; //list<pair<string, int>> table = {{"0123456789012345", 0}}; function<string(const pair<const string, int>&)> get_first = bind(&pair<const string, int>::first, _1); auto it = find_if(table.begin(), table.end(), bind(greater<size_t>(), bind(&string::length, bind(get_first, _1)), 5)); assert(it != table.end()); return 0; } Here is the result of compiling: -------------------------------------------------------------- prospero% g++ -v -save-temps -std=c++11 -Wall -g -I../include -ftemplate-depth=10000 a.cpp 2>&1 Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/home/jpr/LOCAL/test/gcc-4.8.1/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../configure --prefix=/user/jpr/home/LOCAL/test/gcc-4.8.1 --with-local-prefix=/user/jpr/home/LOCAL/test/gcc-4.8.1 --enable-threads --enable-languages=ada,c,c++,fortran,objc,obj-c++,go,java --with-gmp-lib=/usr/lib64 --with-mpfr-lib=/usr/lib64 --with-mpc-lib=/usr/lib64 Thread model: posix gcc version 4.8.1 (GCC) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++11' '-Wall' '-g' '-I' '../include' '-ftemplate-depth=10000' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /home/jpr/LOCAL/test/gcc-4.8.1/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/cc1plus -E -quiet -v -I ../include -iprefix /home/jpr/LOCAL/test/gcc-4.8.1/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.1/ -D_GNU_SOURCE a.cpp -mtune=generic -march=x86-64 -std=c++11 -Wall -ftemplate-depth=10000 -g -fworking-directory -fpch-preprocess -o a.ii ignoring nonexistent directory "/home/jpr/LOCAL/test/gcc-4.8.1/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../x86_64-unknown-linux-gnu/include" ignoring duplicate directory "/home/jpr/LOCAL/test/gcc-4.8.1/bin/../lib/gcc/../../lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../include/c++/4.8.1" ignoring duplicate directory "/home/jpr/LOCAL/test/gcc-4.8.1/bin/../lib/gcc/../../lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../include/c++/4.8.1/x86_64-unknown-linux-gnu" ignoring duplicate directory "/home/jpr/LOCAL/test/gcc-4.8.1/bin/../lib/gcc/../../lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../include/c++/4.8.1/backward" ignoring duplicate directory "/home/jpr/LOCAL/test/gcc-4.8.1/bin/../lib/gcc/../../lib/gcc/x86_64-unknown-linux-gnu/4.8.1/include" ignoring duplicate directory "/home/jpr/LOCAL/test/gcc-4.8.1/bin/../lib/gcc/../../lib/gcc/x86_64-unknown-linux-gnu/4.8.1/include-fixed" ignoring nonexistent directory "/home/jpr/LOCAL/test/gcc-4.8.1/bin/../lib/gcc/../../lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../x86_64-unknown-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: ../include /home/jpr/LOCAL/test/gcc-4.8.1/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../include/c++/4.8.1 /home/jpr/LOCAL/test/gcc-4.8.1/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../include/c++/4.8.1/x86_64-unknown-linux-gnu /home/jpr/LOCAL/test/gcc-4.8.1/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../include/c++/4.8.1/backward /home/jpr/LOCAL/test/gcc-4.8.1/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.1/include /home/jpr/LOCAL/test/gcc-4.8.1/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.1/include-fixed /user/jpr/home/LOCAL/test/gcc-4.8.1/include /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++11' '-Wall' '-g' '-I' '../include' '-ftemplate-depth=10000' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /home/jpr/LOCAL/test/gcc-4.8.1/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/cc1plus -fpreprocessed a.ii -quiet -dumpbase a.cpp -mtune=generic -march=x86-64 -auxbase a -g -Wall -std=c++11 -version -ftemplate-depth=10000 -o a.s GNU C++ (GCC) version 4.8.1 (x86_64-unknown-linux-gnu) compiled by GNU C version 4.8.1, GMP version 5.0.2, MPFR version 3.1.0, MPC version 0.9 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C++ (GCC) version 4.8.1 (x86_64-unknown-linux-gnu) compiled by GNU C version 4.8.1, GMP version 5.0.2, MPFR version 3.1.0, MPC version 0.9 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: f1ad4865ded0b3f0e4317ac2d8456db9 In file included from /home/jpr/LOCAL/test/gcc-4.8.1/include/c++/4.8.1/bits/stl_algo.h:66:0, from /home/jpr/LOCAL/test/gcc-4.8.1/include/c++/4.8.1/algorithm:62, from a.cpp:5: /home/jpr/LOCAL/test/gcc-4.8.1/include/c++/4.8.1/functional:1138:35: error: template instantiation depth exceeds maximum of 10000 (use -ftemplate-depth= to increase the maximum) substituting ‘template<class _Tp> typename std::add_rvalue_reference< <template-parameter-1-1> >::type std::declval() [with _Tp = std::pair<const std::basic_string<char>, int>&]’ -> decltype(__arg(declval<_Args>()...)) ^ /home/jpr/LOCAL/test/gcc-4.8.1/include/c++/4.8.1/functional:1391:40: recursively required by substitution of ‘template<class _CVArg, class ... _Args> decltype (__arg((declval<_Args>)()...)) std::_Mu<_Arg, true, false>::operator()(_CVArg&, std::tuple<_Args2 ...>&) const volatile [with _CVArg = _CVArg; _Args = {_Args ...}; _Arg = std::_Bind<std::function<std::basic_string<char>(const std::pair<const std::basic_string<char>, int>&)>(std::_Placeholder<1>)>] [with _CVArg = const volatile std::_Bind<std::function<std::basic_string<char>(const std::pair<const std::basic_string<char>, int>&)>(std::_Placeholder<1>)>; _Args = {std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>&}]’ /home/jpr/LOCAL/test/gcc-4.8.1/include/c++/4.8.1/functional:1391:40: required by substitution of ‘template<class _CVArg, class ... _Args, long unsigned int ..._Indexes> decltype (__arg((declval<_Args>)()...)) std::_Mu<_Arg, true, false>::__call(_CVArg&, std::tuple<_Args2 ...>&, const std::_Index_tuple<_Indexes ...>&) const volatile [with _CVArg = _CVArg; _Args = {_Args ...}; long unsigned int ..._Indexes = {_Indexes ...}; _Arg = std::_Bind<std::_Mem_fn<long unsigned int (std::basic_string<char>::*)()const>(std::_Bind<std::function<std::basic_string<char>(const std::pair<const std::basic_string<char>, int>&)>(std::_Placeholder<1>)>)>] [with _CVArg = std::_Bind<std::_Mem_fn<long unsigned int (std::basic_string<char>::*)()const>(std::_Bind<std::function<std::basic_string<char>(const std::pair<const std::basic_string<char>, int>&)>(std::_Placeholder<1>)>)>; _Args = {std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>&}; long unsigned int ..._Indexes = {0ul}]’ /home/jpr/LOCAL/test/gcc-4.8.1/include/c++/4.8.1/functional:1143:50: template instantiation depth exceeds maximum of 10000 (use -ftemplate-depth= to increase the maximum) substituting ‘template<class _Tp> typename std::add_rvalue_reference< <template-parameter-1-1> >::type std::declval() [with _Tp = std::pair<const std::basic_string<char>, int>&]’ /home/jpr/LOCAL/test/gcc-4.8.1/include/c++/4.8.1/functional:1391:40: recursively required by substitution of ‘template<class _CVArg, class ... _Args> decltype (__arg((declval<_Args>)()...)) std::_Mu<_Arg, true, false>::operator()(_CVArg&, std::tuple<_Args2 ...>&) const volatile [with _CVArg = _CVArg; _Args = {_Args ...}; _Arg = std::_Bind<std::function<std::basic_string<char>(const std::pair<const std::basic_string<char>, int>&)>(std::_Placeholder<1>)>] [with _CVArg = const volatile std::_Bind<std::function<std::basic_string<char>(const std::pair<const std::basic_string<char>, int>&)>(std::_Placeholder<1>)>; _Args = {std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>&}]’ ... FOLLOWED BY A LOT OF SIMILAR MESSAGES... -------------------------------------------------------------- Note that - I increased the -ftemplate-depth parameter to 10000; indeed, it seems to be an infinite loop; - replacing the map by a list (commented line) does not change anything; the error messages are similar; - compilation also fails with the same messages on MacOS 1.8.4 with g++-4.8.1 (MacPorts gcc48 4.8-20130404_1) - The same program compiles (and works) correctly with g++-4.7.2 '4.7.2 20120921 (Red Hat 4.7.2-2)). Regards Jean-Paul Rigault