Skip to content

Missing __VA_ARGS__ extension in Microsoft mode #13217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
llvmbot opened this issue May 16, 2012 · 8 comments
Closed

Missing __VA_ARGS__ extension in Microsoft mode #13217

llvmbot opened this issue May 16, 2012 · 8 comments
Labels
bugzilla Issues migrated from bugzilla c++

Comments

@llvmbot
Copy link
Member

llvmbot commented May 16, 2012

Bugzilla Link 12845
Resolution FIXED
Resolved on May 17, 2018 09:16
Version trunk
OS Windows NT
Blocks llvm/llvm-bugzilla-archive#13707
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@efriedma-quic,@tritao,@nico

Extended Description

When passing a single argument to a macro which defines a function with a variable arguments list as its' second argument, Clang will incorrectly preprocess such code, leaving the unnecessary comma after the first argument, thus making the resulting code uncompilable. Consider the example:

bool MsgAlert(bool yes_no, int Style, const char* format, ...)
{return true;}
#define PanicAlert(format, ...) MsgAlert(false, 1, format, VA_ARGS)

void func()
{PanicAlert("text");}

Clang preprocessor (the -E flag, in MS compatibility mode) will generate the following (note the excessive comma after "text"):

void func()
{MsgAlert(false, 1, "text", );}

In comparison, the MSVC preprocessor (cl.exe) will generate the correct code:

void func()
{MsgAlert(false, 1, "text" );}

@efriedma-quic
Copy link
Collaborator

gcc has a very similar extension... but not quite the same. :(

@llvmbot
Copy link
Member Author

llvmbot commented Jun 29, 2012

Note that MS will allow empty argument list and remove the trailing comma even when compiling with /Za (disable language extensions).

@llvmbot
Copy link
Member Author

llvmbot commented Jun 29, 2012

Also, the trailing comma is removed, even if the VA_ARGS is followed by the pasting operator:

#define FOO(x, ...) int a((x, __VA_ARGS__ ## 1))
FOO(1); // error: missing ')'

@llvmbot
Copy link
Member Author

llvmbot commented Jun 29, 2012

Patch: avakar/clang@bug_12845

@tritao
Copy link
Mannequin

tritao mannequin commented Aug 25, 2012

Can you send your patch to cfe-commits?

@llvmbot
Copy link
Member Author

llvmbot commented Aug 27, 2012

Can you send your patch to cfe-commits?

Sure, I'll write tests for it and send it.

@nico
Copy link
Contributor

nico commented May 17, 2018

This seems to be working now.

@tritao
Copy link
Mannequin

tritao mannequin commented Nov 26, 2021

mentioned in issue llvm/llvm-bugzilla-archive#13707

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++
Projects
None yet
Development

No branches or pull requests

3 participants