<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Incorrect macro expansion in clang on Windows with VC++ target"
   href="http://llvm.org/bugs/show_bug.cgi?id=20277">20277</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Incorrect macro expansion in clang on Windows with VC++ target
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows XP
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Driver
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>eldlistmailingz@tropicsoft.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Clang is not doing macro expansion correctly in an instance which I will show.
The build is clang on Windows targeting VC++ built from the latest trunk. The
source is:

# define REM(...) __VA_ARGS__
# define EAT(...)
# define CAT(a, b) CAT_I(a, b)
# define CAT_I(a, b) a ## b
# define LPAREN() (
# define RPAREN() )
# define COMMA() ,
# define STL(seq) STL_I(SBT(seq))
# define STL_I(bseq) STL_A bseq NIL STL_B bseq
# define STL_A(m, e) m(LPAREN() e COMMA() STL_A_ID)
# define STL_A_ID() STL_A
# define STL_B(m, e) m(RPAREN() STL_B_ID)
# define STL_B_ID() STL_B
# define SBT(seq) CAT(SBT_A seq, 0)
# define SBT_A(...) (SBT_GET_REM(__VA_ARGS__), __VA_ARGS__)() SBT_B
# define SBT_B(...) (SBT_GET_REM(__VA_ARGS__), __VA_ARGS__)() SBT_A
# define SBT_GET_REM(...) REM
# define SBT_A0 (EAT, ?)
# define SBT_B0 (EAT, ?)

int main()
{
STL(())
return 0;
}

The expansion of STL should be:

(,BOOST_PP_NIL)

Admittedly placed in a CPP main function this should lead to a compiler error
etc. since '(, BOOST_PP_NIL )' by itself as C++ is invalid, but I have included
it in this way to keep things simple and to show that the macro expansion
itself is valid. The point is that clang.exe gives these errors trying to
expand the macro:

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

seq_clang_failure.cpp(23,1) :  error: too few arguments provided to
function-like macro invocation
STL(())
^
seq_clang_failure.cpp(8,25) :  note: expanded from macro 'STL'
# define STL(seq) STL_I(SBT(seq))
                        ^
seq_clang_failure.cpp(14,23) :  note: expanded from macro 'SBT'
# define SBT(seq) CAT(SBT_A seq, 0)
                      ^
seq_clang_failure.cpp(15,59) :  note: expanded from macro 'SBT_A'
# define SBT_A(...) (SBT_GET_REM(__VA_ARGS__), __VA_ARGS__)() SBT_B
                                                          ^
seq_clang_failure.cpp(3,26) :  note: expanded from macro 'CAT'
# define CAT(a, b) CAT_I(a, b)
                         ^
seq_clang_failure.cpp(4,22) :  note: expanded from macro 'CAT_I'
# define CAT_I(a, b) a ## b
                     ^
seq_clang_failure.cpp(9,28) :  note: expanded from macro 'STL_I'
# define STL_I(bseq) STL_A bseq NIL STL_B bseq
                           ^
seq_clang_failure.cpp(10,10) :  note: macro 'STL_A' defined here
# define STL_A(m, e) m(LPAREN() e COMMA() STL_A_ID)
         ^
seq_clang_failure.cpp(23,1) :  error: use of undeclared identifier 'STL_A'
STL(())
^
seq_clang_failure.cpp(8,19) :  note: expanded from macro 'STL'
# define STL(seq) STL_I(SBT(seq))
                  ^
seq_clang_failure.cpp(9,22) :  note: expanded from macro 'STL_I'
# define STL_I(bseq) STL_A bseq NIL STL_B bseq
                     ^
seq_clang_failure.cpp(23,1) :  error: use of undeclared identifier 'EAT'
seq_clang_failure.cpp(8,25) :  note: expanded from macro 'STL'
# define STL(seq) STL_I(SBT(seq))
                        ^
seq_clang_failure.cpp(14,19) :  note: expanded from macro 'SBT'
# define SBT(seq) CAT(SBT_A seq, 0)
                  ^
seq_clang_failure.cpp(3,20) :  note: expanded from macro 'CAT'
# define CAT(a, b) CAT_I(a, b)
                   ^
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see
all)
<scratch space>(2,1) :  note: expanded from here
SBT_B0
^
seq_clang_failure.cpp(19,18) :  note: expanded from macro 'SBT_B0'
# define SBT_B0 (EAT, ?)
                 ^
seq_clang_failure.cpp(9,28) :  note: expanded from macro 'STL_I'
# define STL_I(bseq) STL_A bseq NIL STL_B bseq
                           ^
seq_clang_failure.cpp(23,1) :  error: too few arguments provided to
function-like macro invocation
seq_clang_failure.cpp(8,25) :  note: expanded from macro 'STL'
# define STL(seq) STL_I(SBT(seq))
                        ^
seq_clang_failure.cpp(14,23) :  note: expanded from macro 'SBT'
# define SBT(seq) CAT(SBT_A seq, 0)
                      ^
seq_clang_failure.cpp(15,59) :  note: expanded from macro 'SBT_A'
# define SBT_A(...) (SBT_GET_REM(__VA_ARGS__), __VA_ARGS__)() SBT_B
                                                          ^
seq_clang_failure.cpp(3,26) :  note: expanded from macro 'CAT'
# define CAT(a, b) CAT_I(a, b)
                         ^
seq_clang_failure.cpp(4,22) :  note: expanded from macro 'CAT_I'
# define CAT_I(a, b) a ## b
                     ^
seq_clang_failure.cpp(9,43) :  note: expanded from macro 'STL_I'
# define STL_I(bseq) STL_A bseq NIL STL_B bseq
                                          ^
seq_clang_failure.cpp(12,10) :  note: macro 'STL_B' defined here
# define STL_B(m, e) m(RPAREN() STL_B_ID)
         ^

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

The code is actually taken from Boost PP from the BOOST_PP_SEQ_TO_LIST
functionality when using clang. I have simplified its presentation as a bug 
for convenience. A '()' is a valid Boost PP seq and '(,BOOST_PP_NIL)' is a
valid Boost PP list. The STL macro is just my shorthand for the actual
BOOST_PP_SEQ_TO_LIST.

This is a serious bug. Doing straightforward macro expansion should not fail in
clang. The macro expansion exceeds in all versions of gcc, as well as in the
Boost Wave driver. So unless clang know something that I do not know about
macro expansion in the latest C++, this needs to be fixed.

The command line parameters are:

-TP /Od /Ob0 /W3 /GR /MDd  /Zc:forScope /Zc:wchar_t -fmsc-version=1800 /wd4675
/EHs -c

This is being compiled by the Boost Build system on Windows 7 Ultimate SP1,
with the latest clang.exe built successfully in Visual Studio 2012 using the
release build.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>