http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59702
Bug ID: 59702
Summary: Infinite recursion in a late-specified return type of
a function template
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ville.voutilainen at gmail dot com
struct A {};
template<typename>
int func (A) {
return {};
}
template<typename T>
auto func () -> decltype (func<T> (A{})) {
return {};
}
int
main (int argc, char *argv[])
{
func<int> ();
}
Result:
edoceo8.cpp:9:39: error: template instantiation depth exceeds maximum of 900
(use -ftemplate-depth= to increase the maximum) substituting ‘template<class T>
decltype (func<T>(A{})) func() [with T = int]’
auto func () -> decltype (func<T> (A{})) {
^
edoceo8.cpp:9:39: recursively required by substitution of ‘template<class T>
decltype (func<T>(A{})) func() [with T = int]’
edoceo8.cpp:9:39: required by substitution of ‘template<class T> decltype
(func<T>(A{})) func() [with T = int]’
edoceo8.cpp:16:14: required from here
edoceo8.cpp: In function ‘int main(int, char**)’:
edoceo8.cpp:16:14: error: no matching function for call to ‘func()’
func<int> ();
^
edoceo8.cpp:16:14: note: candidates are:
edoceo8.cpp:4:5: note: template<class> int func(A)
int func (A) {
^
edoceo8.cpp:4:5: note: template argument deduction/substitution failed:
edoceo8.cpp:16:14: note: candidate expects 1 argument, 0 provided
func<int> ();
^
edoceo8.cpp:9:6: note: template<class T> decltype (func<T>(A{})) func()
auto func () -> decltype (func<T> (A{})) {
^
edoceo8.cpp:9:6: note: substitution of deduced template arguments resulted in
errors seen above
It doesn't seem to me like the late-specified return type is even referring to
the return type of the latter function template.