diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Lex/TokenLexer.cpp | 7 | ||||
-rw-r--r-- | clang/test/Preprocessor/macro_paste_msextensions.c | 7 |
2 files changed, 14 insertions, 0 deletions
diff --git a/clang/lib/Lex/TokenLexer.cpp b/clang/lib/Lex/TokenLexer.cpp index 23d72814f31..83efbab7613 100644 --- a/clang/lib/Lex/TokenLexer.cpp +++ b/clang/lib/Lex/TokenLexer.cpp @@ -521,6 +521,13 @@ bool TokenLexer::Lex(Token &Tok) { /// are more ## after it, chomp them iteratively. Return the result as Tok. /// If this returns true, the caller should immediately return the token. bool TokenLexer::PasteTokens(Token &Tok) { + // MSVC: If previous token was pasted, this must be a recovery from an invalid + // paste operation. Ignore spaces before this token to mimic MSVC output. + // Required for generating valid UUID strings in some MS headers. + if (PP.getLangOpts().MicrosoftExt && (CurToken >= 2) && + Tokens[CurToken - 2].is(tok::hashhash)) + Tok.clearFlag(Token::LeadingSpace); + SmallString<128> Buffer; const char *ResultTokStrPtr = nullptr; SourceLocation StartLoc = Tok.getLocation(); diff --git a/clang/test/Preprocessor/macro_paste_msextensions.c b/clang/test/Preprocessor/macro_paste_msextensions.c index afdcdbd493f..aa5f41f9ee4 100644 --- a/clang/test/Preprocessor/macro_paste_msextensions.c +++ b/clang/test/Preprocessor/macro_paste_msextensions.c @@ -32,3 +32,10 @@ nested(baz) rise of the dead tokens bar(q) // CHECK: abc(baz(q)) + + +#define str(x) #x +#define collapse_spaces(a, b, c, d) str(a ## - ## b ## - ## c ## d) +collapse_spaces(1a, b2, 3c, d4) + +// CHECK: "1a-b2-3cd4" |