[cfe-dev] Another clang-cl preprocessor problem

Edward Diener via cfe-dev cfe-dev at lists.llvm.org
Sat Apr 16 01:36:09 PDT 2016

I posted bug 27382 at https://llvm.org/bugs/show_bug.cgi?id=27382, which 
illustrates a problem with clang-cl's emulation of VC++. The code is:

#define TEST_EXPAND_I(x) x
#define TEST_REM(...) __VA_ARGS__

#define TEST_CAT(a, b) TEST_CAT_I(a, b)
#define TEST_CAT_I(a, b) a ## b

#define TEST_ELEM(n, ...) TEST_ELEM_I(n,__VA_ARGS__)
#define TEST_ELEM_I(n, ...) TEST_CAT(TEST_CAT(TEST_ELEM_, n)(__VA_ARGS__,),)
#define TEST_ELEM_0(e0, ...) e0
#define TEST_ELEM_1(e0, e1, ...) e1


int main()
     int x = TEST_MACRO(1,(1,0));
     return x;

VC++14 compiles this without error. Clang-cl gives:

test_clang2.cpp(17,29):  error: too many arguments provided to 
function-like macro invocation
     int x = TEST_MACRO(1,(1,0));
test_clang2.cpp(2,9):  note: macro 'TEST_EXPAND_I' defined here
#define TEST_EXPAND_I(x) x
test_clang2.cpp(17,32):  error: expected expression
     int x = TEST_MACRO(1,(1,0));

My reason for posting this here is not to embarrass clang but in case 
anybody knows of a compiler option workaround. I am discovering problems 
testing the Boost Preprocessor library with clang-cl, and the above code 
is a simplified version of code in Boost PP which illustates the 
problem. The clang-cl compiler options used are:

-TP /Od /Ob0 /W3 /GR /MDd  /Zc:forScope /Zc:wchar_t -fmsc-version=1900 
/wd4675 /EHs -fmacro-backtrace-limit=0 -Wno-invalid-token-paste -c

More information about the cfe-dev mailing list