Reputation: 75150
I'm having a problem with this code:
#include <iostream>
using namespace std;
class A {
public:
template<typename T, typename... Args>
void stuff(Args... args);
};
template<typename T, typename... Args>
void A::stuff(Args... args) {
cout << sizeof...(args) << endl;
}
template<>
void A::stuff<int>() {
cout << "int" << endl;
}
int main() {
A a;
A b;
a.stuff<char>();
b.stuff<int>();
}
Trying to compile it, I get this error:
template-id 'stuff<int>' for 'void A::stuff()' does not match any template declaration
What am I doing wrong? I tried it without the variadicness and it worked, but how do I specialise a variadic template member function?
Upvotes: 4
Views: 1553
Reputation: 111250
This looks like a bug. The problem is not limited to fully-specialized member function templates. It can be reproduced even with free-function templates as follows:
template<typename T, typename... Args>
void stuff2(Args... args);
template<typename T, typename... Args>
void stuff2(Args... args) {
cout << sizeof...(args) << endl;
}
template<>
void stuff2<int>() {
cout << "int" << endl;
}
int main() {}
While clang 3.2 compiles this just fine, gcc complains about:
spec.cpp:31:6: error: template-id 'stuff2' for 'void stuff2()' does not match any template declaration
There is a related SO question.
A message seems to confirm that this is indeed a bug.
Upvotes: 5