I was just surprised that providing a type with two template arguments to a function-like macro led to a compiler complaint.
This (conceptually similar) sample code:
template<typename T> struct foo{};
template<typename T, U> struct bar{};
#define p(x) printf("sizeof(" #x ") = %u\n", sizeof(x));
int main()
{
p(foo<int>);
p(bar<int,int>);
p((bar<int,int>));
return 0;
}
makes GCC (6.2.0) a complaint macro "p" passed 2 arguments, but takes just 1.
Well, of course, a preprocessor is a preprocessor that performs text replacement, it is not a true C ++ compiler that understands patterns or all other language rules.
Maybe I ask too much, expecting the preprocessor to recognize the angle brackets provided ... but at least the parentheses are explicitly mentioned in the specification.
16.3 ( 10-12) , . "outermost" , ( ) , .
, " ", " " - , , .
?