This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: [C++11] recursive late-specified return type
- From: Miles Bader <miles at gnu dot org>
- To: Nathan Ridge <zeratul976 at hotmail dot com>
- Cc: GCC Help Mailing List <gcc-help at gcc dot gnu dot org>
- Date: Mon, 07 Nov 2011 18:21:19 +0900
- Subject: Re: [C++11] recursive late-specified return type
- References: <BLU162-W310DC9F5BEA9478EDAF92296D90@phx.gbl>
Nathan Ridge <zeratul976@hotmail.com> writes:
> 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?
I can't answer this question, but it will compile if you use
std::common_type<>, from <type_traits> to calculate the return
type.... e.g.:
#include <type_traits>
...
template <class T, class... P>
auto sum(const T& t, const P&... p) -> typename common_type<T, P...>::type
{
return t + sum(p...);
}
I can imagine that the reason your version might not compile is
because you're trying to use the multi-parameter version of sum, in
"decltype (t + sum (p...))" before the multi-parameter version of sum
has been fully declared (as the decltype is part of that declaration);
I dunno whether the compiler is supposed to handle that or not...
-Miles
--
Corporation, n. An ingenious device for obtaining individual profit without
individual responsibility.