[PATCH] Emulate MSVC handling of commas during macro arg expansion

Will Wilson will at indefiant.com
Tue Jun 25 14:44:35 PDT 2013


Hi All,

This patch is a rework of João's original patch applied as r163022 and
later reverted in r164672. I've spent a few (long...) days attempting to
get to the bottom of what caused the failures that led to the original
patch being reverted. This should fix (once and for all) the error seen
when compiling VS2012 type_traits and by extension most of the VS2012
STL headers:

In file included from C:\Program Files (x86)\Microsoft Visual Studio
11.0\VC\include\type_traits:1820:
C:\Program Files (x86)\Microsoft Visual Studio
11.0\VC\include\xrefwrap(156,20): error : too many arguments provided to
function-like macro invocation


The main changes in this patch are:

   - Tokens used as macro arguments that expand to a *single* comma have
   special treatment - the comma will not be treated as a macro argument
   separator in MicrosoftMode. Tokens that expand into multiple tokens that
   may include commas are treated normally.
   - I've reused 0x04 for the IgnoredComma flag as the other case
   (DisableExpand) is exclusively used for identifiers and won't conflict with
   tok::comma. It didn't seem worth using up an entirely new value for such a
   rare edge case as this.

In terms of testing, clang should now be able to compile VS2012
type_traits. I tested successfully against Nico's original GTest test case (
PR13924) and against boost.python 1.42.0 which also failed with the
original patch. I've also added a new test case based on the VS2012 xstddef
macros that led to the patch being needed in the first place.

All tests passed against latest trunk. Please review and commit if it
LGTY...

Cheers,
Will.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130625/4bfd2ab0/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: msvc_macros_commas.patch
Type: application/octet-stream
Size: 3459 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130625/4bfd2ab0/attachment.obj>


More information about the cfe-commits mailing list