http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58527
Bug ID: 58527
Summary: Failures when a function parameter pack is not final
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: nmm1 at cam dot ac.uk
This may be already reported, but I can't see how to search for it. Sorry.
#include <iostream>
using namespace std;
template<typename ... Pack>
void weeble(Pack ... rest, double x) {
int y[] = {rest...};
for (int i = 0; i < sizeof(y)/sizeof(*y); ++i) cout << y[i] << " ";
cout << x << endl;
}
int main () {
weeble(123,456,789,3.1416);
}
fails with:
junk.cpp: In function 'int main()':
junk.cpp:12:30: error: no matching function for call to 'weeble(int, int, int,
double)'
weeble(123,456,789,3.1416);
^
junk.cpp:12:30: note: candidate is:
junk.cpp:5:6: note: template<class ... Pack> void weeble(Pack ..., double)
void weeble(Pack ... rest, double x) {
^
junk.cpp:5:6: note: template argument deduction/substitution failed:
junk.cpp:12:30: note: candidate expects 1 argument, 4 provided
weeble(123,456,789,3.1416);
^
Now, it may well be illegal, though I can't spot anything in C++11.
It would certainly be illegal if it were the <cstdarg> 'equivalent'.
But it is parsable, in theory, even more so in my original form.
However, that's not my sole point. If it is illegal, why isn't it
being rejected when the function template is being parsed, rather than
left to type resolution to fail weirdly? Intel is even more amusing,
incidentally :-)
Other information:
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/home/nmm/GCC/libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --prefix=/home/nmm/GCC --disable-bootstrap
--enable-languages=c,c++,fortran --enable-werror=yes --disable-decimal-float
Thread model: posix
gcc version 4.8.1 (GCC)
COLLECT_GCC_OPTIONS='-std=c++11' '-Wall' '-Wextra' '-Wno-unused-parameter'
'-fno-elide-constructors' '-g' '-O3' '-I' '/home/nmm/Courses/C++/Includes' '-I'
'.' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
Linux wheeler 2.6.37.6-24-desktop #1 SMP PREEMPT 2012-10-18 22:36:08 +0200
x86_64 x86_64 x86_64 GNU/Linux