This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++11] recursive late-specified return type


Hi,

Could someone please clarify whether the following code (from [1]),
which GCC trunk rejects, is valid (i.e. the error is a bug) or invalid?

#include <iostream>
using namespace std;

template <class T>
T sum(const T& in)
{
?? return in;
}

template <class T, class... P>
auto sum(const T& t, const P&... p) -> decltype(t + sum(p...))
{
?? return t + sum(p...);
}

int main()
{
?? cout << sum(5, 10.0, 22.2) << endl;
}

Errors:

test.cpp: In function 'int main()':
test.cpp:18:29: error: no matching function for call to 'sum(int, double, double)'
test.cpp:18:29: note: candidates are:
test.cpp:5:3: note: template<class T> T sum(const T&)
test.cpp:5:3: note:?? template argument deduction/substitution failed:
test.cpp:18:29: note:?? candidate expects 1 argument, 3 provided
test.cpp:11:6: note: template<class T, class ... P> decltype ((t + sum(sum::p ...))) sum(const T&, const P& ...)
test.cpp:11:6: note:?? template argument deduction/substitution failed:
test.cpp: In substitution of 'template<class T, class ... P> decltype ((t + sum(p ...))) sum(const T&, const P& ...) [with T = int; P = {double, double}]':
test.cpp:18:29:?? required from here
test.cpp:11:6: error: no matching function for call to 'sum(const double&, const double&)'
test.cpp:11:6: note: candidate is:
test.cpp:5:3: note: template<class T> T sum(const T&)
test.cpp:5:3: note:?? template argument deduction/substitution failed:
test.cpp:11:6: note:?? candidate expects 1 argument, 2 provided

Thanks,
Nate

[1] http://stackoverflow.com/questions/8023332/recursive-trailing-return-type)


 		 	   		  


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]