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 to void (int).
void ((int)) part in foo<void ((int))> is called type-id.
According to §8.1/1, type-id is composed of
type-specifier-seq and abstract-declarator.
In void ((int)), type-specifier-seq is void and abstract-declarator
is ((int)),
and abstract-declarator can be parenthesized arbitrarily.
This is legal in C and C++.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With