This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
C++11 - Parameter pack question
- From: Sidney Marshall <sidneym at frontiernet dot net>
- To: gcc-help at gcc dot gnu dot org
- Cc: sidneym at frontiernet dot net
- Date: Fri, 15 Aug 2014 21:13:48 -0400
- Subject: C++11 - Parameter pack question
- Authentication-results: sourceware.org; auth=none
Hello,
The following code compiles and runs correctly but gives a warning:
----------------------------------------
#include<iostream>
using namespace std;
template<class T>
T sum(T value) {
return value;
}
template<class T, class ... U>
auto sum(T value, U ... values) {
return value + sum(values ...);
}
int main() {
cout << sum(1, 2, 4.6) << endl;
cout << sum(1, "abcde", 2) << endl;
}
--------------------------------------
$ g++ -std=c++11 pack.cpp
pack.cpp:11:31: warning: â??sumâ?? function uses
â??autoâ?? type specifier without trailing return type [enabled by default]
auto sum(T value, U ... values) {
$ ./a.exe
7.6
de
-------------------------------------------
All of my attempts to use a trailing return type
failed (and I believe should have failed according to the standard).
My two questions:
1. What possible user mistake is the warning worried about?
2. How can I write my code with better style so that there is no warning?
Thank you.
--Sidney Marshall