From: Nathan Ridge <zeratul976@hotmail.com>
To: GCC Help Mailing List <gcc-help@gcc.gnu.org>
Subject: [C++11] recursive late-specified return type
Date: Mon, 07 Nov 2011 07:41:00 -0000 [thread overview]
Message-ID: <BLU162-W310DC9F5BEA9478EDAF92296D90@phx.gbl> (raw)
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)
next reply other threads:[~2011-11-07 7:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-07 7:41 Nathan Ridge [this message]
2011-11-07 9:21 ` Miles Bader
2011-11-10 23:37 ` Nathan Ridge
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=BLU162-W310DC9F5BEA9478EDAF92296D90@phx.gbl \
--to=zeratul976@hotmail.com \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).