Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Andrei_P_1
Beginner
111 Views

ICC 2017 Preprocessor bug with tokens concatenation

Hello. I'm found a bug with tokens concatenationSimple example to reproduce:

#define test(x, y) sizeof(x##y)
#define test2(x, y) sizeof(##x##y)
int main()
{
	int a = test(in, t); // works fine
	int b = test2(in, t); // error
}

Compilation on windows (msvc integration):

1>  main.cpp
1>..\main.cpp(6): error : identifier "in" is undefined
1>    	int b = test2(in, t); // error
1>    	        ^
1>  
1>..\main.cpp(6): error : expected a ")"
1>    	int b = test2(in, t); // error

Preprocessor output to file:

#line 1 "..\\main.cpp"

int main()
{
	int a = sizeof(int); 
	int b = sizeof(int); 
}

 

0 Kudos
2 Replies
Judith_W_Intel
Employee
111 Views

 

You are correct that we should try to emulate what Microsoft is doing, but your code is definitely incorrect according to the standard.

The GNU compiler gives this error:

sptxl15-134> g++ -c main.cpp
main.cpp:9:1: error: pasting "(" and "in" does not give a valid preprocessing token
sptxl15-135>

The token paste operator must result in a valid token and the second expansion does not have one.

https://gcc.gnu.org/onlinedocs/cpp/Concatenation.html

 

Andrei_P_1
Beginner
111 Views

Thanks for the answer. I am found it by accident, when a working project didn't builded after replacing MSVC to ICC 17. The similar code also worked with ICC for linux. So, I was thinked that it's a bug. But in fact, the work of this code is not necessary, this situation was caused by a typo when copypasting. It will be enough to display a correct error message like it does GCC.

Reply