I have the following code, it compiles with gcc 4.4 with no warnings, and returns 42.
template<typename T>
struct foo
{ };
template<typename T>
struct foo<void (T)>
{
enum { value = 42 };
};
int main()
{
return foo<void ((int))>::value;
}
Now, I see why it should work when the template parameter is void (int), but what’s the deal with the double parentheses? Is this legal in C++? Is it the same as void (int)?
Cheers
In this case,
void ((int))is identical tovoid (int).void ((int))part infoo<void ((int))>is calledtype-id.According to §8.1/1,
type-idis composed oftype-specifier-seqandabstract-declarator.In
void ((int)),type-specifier-seqisvoidandabstract-declaratoris
((int)),and
abstract-declaratorcan be parenthesized arbitrarily.This is legal in C and C++.