diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -25,6 +25,7 @@ #include "clang/Lex/ExternalPreprocessorSource.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/LexDiagnostic.h" +#include "clang/Lex/LiteralSupport.h" #include "clang/Lex/MacroArgs.h" #include "clang/Lex/MacroInfo.h" #include "clang/Lex/Preprocessor.h" @@ -1813,7 +1814,14 @@ if (!Tok.isAnnotation() && Tok.getIdentifierInfo()) Tok.setKind(tok::identifier); - else { + else if (Tok.is(tok::string_literal) && !Tok.hasUDSuffix()) { + StringLiteralParser Literal(Tok, *this); + if (Literal.hadError) + return; + + Tok.setIdentifierInfo(getIdentifierInfo(Literal.GetString())); + Tok.setKind(tok::identifier); + } else { Diag(Tok.getLocation(), diag::err_pp_identifier_arg_not_identifier) << Tok.getKind(); // Don't walk past anything that's not a real token. diff --git a/clang/test/Parser/MicrosoftExtensions.cpp b/clang/test/Parser/MicrosoftExtensions.cpp --- a/clang/test/Parser/MicrosoftExtensions.cpp +++ b/clang/test/Parser/MicrosoftExtensions.cpp @@ -263,6 +263,12 @@ extern int __identifier(and); +int __identifier("baz") = 0; +int bar = baz; + +void mangled_function(); +extern "C" void __identifier("?mangled_function@@YAXXZ")() {} + void f() { __identifier(() // expected-error {{cannot convert '(' token to an identifier}} __identifier(void) // expected-error {{use of undeclared identifier 'void'}} @@ -270,8 +276,10 @@ // FIXME: We should pick a friendlier display name for this token kind. __identifier(1) // expected-error {{cannot convert token to an identifier}} __identifier(+) // expected-error {{cannot convert '+' token to an identifier}} - __identifier("foo") // expected-error {{cannot convert token to an identifier}} __identifier(;) // expected-error {{cannot convert ';' token to an identifier}} + __identifier("1"); // expected-error {{use of undeclared identifier '1'}} + __identifier("+"); // expected-error {{use of undeclared identifier '+'}} + __identifier(";"); // expected-error {{use of undeclared identifier ';'}} } class inline_definition_pure_spec {