[llvm-bugs] [Bug 27380] New: clang-cl preprocessor error where VC++ works

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Apr 15 14:48:10 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=27380

            Bug ID: 27380
           Summary: clang-cl preprocessor error where VC++ works
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: eldlistmailingz at tropicsoft.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

The following code compiles without error using VC++ 14 but gives errors using
the latest clang-cl from the 'trunk':

#define TEST_MACRO(x,y) TEST_EXPAND(2, 0, TEST_SOMETHING(x,y,1))
#define TEST_SOMETHING(x,y,z) 2

#define TEST_EXPAND(...) TEST_EXPAND_I(TEST_OVR(TEST_NAME, __VA_ARGS__),
(__VA_ARGS__))
#define TEST_OVR(name,...) TEST_SOMENAME
#define TEST_EXPAND_I(m, args) TEST_EXPAND_II(m, args)
#define TEST_EXPAND_II(m, args) TEST_CAT(m ## args,)
#define TEST_SOMENAME(x,y,z) ;

#define TEST_CAT(a, b) TEST_CAT_I(a, b)
#define TEST_CAT_I(a, b) TEST_CAT_II(~, a ## b)
#define TEST_CAT_II(p, res) res

int main()
    {
    TEST_MACRO(1,2)
    }

---------------------------------------------------------------------------

The clang errors are:

test_clang.cpp(17,2):  error: pasting formed 'TEST_SOMENAME(', an invalid
preprocessing token [-Winvalid-token-paste]
        TEST_MACRO(1,2)
        ^
test_clang.cpp(2,25):  note: expanded from macro 'TEST_MACRO'
#define TEST_MACRO(x,y) TEST_EXPAND(2, 0, TEST_SOMETHING(x,y,1))
                        ^
test_clang.cpp(5,26):  note: expanded from macro 'TEST_EXPAND'
#define TEST_EXPAND(...) TEST_EXPAND_I(TEST_OVR(TEST_NAME, __VA_ARGS__),
(__VA_ARGS__))
                         ^
test_clang.cpp(7,32):  note: expanded from macro 'TEST_EXPAND_I'
#define TEST_EXPAND_I(m, args) TEST_EXPAND_II(m, args)
                               ^
test_clang.cpp(8,44):  note: expanded from macro 'TEST_EXPAND_II'
#define TEST_EXPAND_II(m, args) TEST_CAT(m ## args,)

----------------------------------------------------------------------------

The clang-cl options are:

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

-----------------------------------------------------------------------------

The VC++14 options when compiling successfully are:

/Zm800 -TP /Z7 /Od /Ob0 /W4 /GR /MDd /Zc:forScope /Zc:wchar_t /wd4675 /EHs -c

---------------------------------------------------------------------------

This example is a simplified version of a failure which occurs when running the
Boost Preprocessor library tests with clang-cl, where the Boost Preprocessor
library is setup to use the exact same workarounds for clang-cl as it does for
VC++, since neither is a C++ standard conforming preprocessor.

A possible fix for this problem is not a change in the code above, even if some
specific change in the code will get clang-cl to work. If clang-cl is truly
emulating the non-standard VC++ preprocessor it must be able to compile
preprocessor code which VC++ also compiles without errors. Thus I am reporting
this problem here.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160415/3b1fd8d5/attachment.html>


More information about the llvm-bugs mailing list