diff options
author | Ehsan Akhgari <ehsan.akhgari@gmail.com> | 2016-01-22 19:26:44 +0000 |
---|---|---|
committer | Ehsan Akhgari <ehsan.akhgari@gmail.com> | 2016-01-22 19:26:44 +0000 |
commit | 34461a626e4fcc72e2facf7dedf8c84cf13e39d2 (patch) | |
tree | 7000fb233aed24e6e36faca36a59a0b00e22d620 /clang/lib/Lex/TokenLexer.cpp | |
parent | acc43d197d7986f4749eeeb85a4c76caa870d452 (diff) | |
download | bcm5719-llvm-34461a626e4fcc72e2facf7dedf8c84cf13e39d2.tar.gz bcm5719-llvm-34461a626e4fcc72e2facf7dedf8c84cf13e39d2.zip |
[MSVC Compat] Accept elided commas in macro function arguments
Summary:
This fixes PR25875. When the trailing comma in a macro argument list is
elided, we need to treat it similarly to the case where a variadic macro
misses one actual argument.
Reviewers: rnk, rsmith
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D15670
llvm-svn: 258530
Diffstat (limited to 'clang/lib/Lex/TokenLexer.cpp')
-rw-r--r-- | clang/lib/Lex/TokenLexer.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/clang/lib/Lex/TokenLexer.cpp b/clang/lib/Lex/TokenLexer.cpp index ed2b8cdabd1..3f66b7f9b76 100644 --- a/clang/lib/Lex/TokenLexer.cpp +++ b/clang/lib/Lex/TokenLexer.cpp @@ -154,12 +154,17 @@ bool TokenLexer::MaybeRemoveCommaBeforeVaArgs( // Remove the comma. ResultToks.pop_back(); - // If the comma was right after another paste (e.g. "X##,##__VA_ARGS__"), - // then removal of the comma should produce a placemarker token (in C99 - // terms) which we model by popping off the previous ##, giving us a plain - // "X" when __VA_ARGS__ is empty. - if (!ResultToks.empty() && ResultToks.back().is(tok::hashhash)) - ResultToks.pop_back(); + if (!ResultToks.empty()) { + // If the comma was right after another paste (e.g. "X##,##__VA_ARGS__"), + // then removal of the comma should produce a placemarker token (in C99 + // terms) which we model by popping off the previous ##, giving us a plain + // "X" when __VA_ARGS__ is empty. + if (ResultToks.back().is(tok::hashhash)) + ResultToks.pop_back(); + + // Remember that this comma was elided. + ResultToks.back().setFlag(Token::CommaAfterElided); + } // Never add a space, even if the comma, ##, or arg had a space. NextTokGetsSpace = false; |