http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59360
Bug ID: 59360
Summary: Complicated bind expression causing infinite recursive
template instantiations
Product: gcc
Version: 4.8.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: eric.niebler at gmail dot com
This code compiles with clang 3.3 but doesn't compile with gcc 4.8.2 with
-std=gnu++11:
#include <vector>
#include <functional>
#include <utility>
#include <iterator>
#include <algorithm>
constexpr struct adjacent_finder
{
template<typename Rng>
typename Rng::const_iterator
operator()(Rng const & rng) const
{
return std::adjacent_find(rng.begin(), rng.end());
}
} adjacent_find {};
constexpr struct ranger
{
template<typename It>
std::pair<It, It>
operator()(It begin, It end) const
{
return std::make_pair(begin, end);
}
} range {};
constexpr struct prever
{
template<typename It>
It operator()(It begin) const
{
return std::prev(begin);
}
} prev {};
constexpr struct ender
{
template<typename Rng>
typename Rng::const_iterator
operator()(Rng const & rng) const
{
return rng.end();
}
} end {};
int main()
{
using std::placeholders::_1;
auto fun = std::bind(
range,
std::bind(adjacent_find, _1),
std::bind(prev, std::bind(end, _1))
);
std::vector<int> vi;
fun(vi);
}
From the error backtrace:
In file included from test2.cpp:2:0:
/usr/local/gcc-4.8.2/include/c++/4.8.2/functional:1138:35: error: template
instantiation depth exceeds maximum of 900 (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::vector<int>&]’
-> decltype(__arg(declval<_Args>()...))
^
/usr/local/gcc-4.8.2/include/c++/4.8.2/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<ender(std::_Placeholder<1>)>] [with _CVArg = const
volatile std::_Bind<ender(std::_Placeholder<1>)>; _Args = {std::vector<int,
std::allocator<int> >&}]’
/usr/local/gcc-4.8.2/include/c++/4.8.2/functional:1391:40: required by
substitution of ‘template<class _CVArg, class ... _Args, 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 ...}; unsigned int ..._Indexes = {_Indexes ...}; _Arg =
std::_Bind<prever(std::_Bind<ender(std::_Placeholder<1>)>)>] [with _CVArg =
std::_Bind<prever(std::_Bind<ender(std::_Placeholder<1>)>)>; _Args =
{std::vector<int, std::allocator<int> >&}; unsigned int ..._Indexes = {0u}]’
/usr/local/gcc-4.8.2/include/c++/4.8.2/functional:1143:50: template
instantiation depth exceeds maximum of 900 (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::vector<int>&]’
[rest snipped...]