[cfe-commits] [Patch] Fix for comma-removal ahead of __VA_ARGS__ in macros

Andy Gibbs andyg1001 at hotmail.co.uk
Sun Nov 4 15:10:50 PST 2012


Hi,

Please could someone review the attached patch for me before I commit it.

This patch fixes the rules surrounding the removal of a leading comma where 
a __VA_ARGS__ expansion is empty.

GCC has the extension, implemented already in clang for...

#define M(...) call(a, ## __VA_ARGS__)

This will expand to "call(a)" for "M()", removing the comma.  However, 
under -std=c99, this behaviour changes so that the comma is not removed. 
The attached patch follows this behaviour when in c99 mode in clang.  In 
gnu99 mode, it behaves as before, and similarly for pre-c99 dialects and for 
c++ (all checked against gcc's behaviour).

Also, Microsoft has a slight variation where "##" can (optionally) be 
omitted:

#define M(...) call(a, __VA_ARGS__)

The patch also implements this when using Microsoft-compatibility mode. 
Details on Microsoft's implementation is at 
http://msdn.microsoft.com/en-us/library/ms177415(v=vs.80).aspx.  I believe 
this also closes out PR12845, which I came across after putting this patch 
together.

Thanks
Andy



 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix.diff
Type: application/octet-stream
Size: 6344 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121105/a53a832e/attachment.obj>


More information about the cfe-commits mailing list