зеркало из https://github.com/microsoft/clang.git
Fix PR5982, a refacto in checking for '=' in a -D argument.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93088 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
8a0d94d2ef
Коммит
1ee4b9e6d2
|
@ -27,19 +27,16 @@ using namespace clang;
|
|||
// in which case we emit "#define XXX 1" or "XXX=Y z W" in which case we emit
|
||||
// "#define XXX Y z W". To get a #define with no value, use "XXX=".
|
||||
static void DefineBuiltinMacro(MacroBuilder &Builder, llvm::StringRef Macro,
|
||||
Diagnostic *Diags = 0) {
|
||||
Diagnostic &Diags) {
|
||||
std::pair<llvm::StringRef, llvm::StringRef> MacroPair = Macro.split('=');
|
||||
llvm::StringRef MacroName = MacroPair.first;
|
||||
llvm::StringRef MacroBody = MacroPair.second;
|
||||
if (!MacroBody.empty()) {
|
||||
if (MacroName.size() != Macro.size()) {
|
||||
// Per GCC -D semantics, the macro ends at \n if it exists.
|
||||
llvm::StringRef::size_type End = MacroBody.find_first_of("\n\r");
|
||||
if (End != llvm::StringRef::npos) {
|
||||
assert(Diags && "Unexpected macro with embedded newline!");
|
||||
Diags->Report(diag::warn_fe_macro_contains_embedded_newline)
|
||||
if (End != llvm::StringRef::npos)
|
||||
Diags.Report(diag::warn_fe_macro_contains_embedded_newline)
|
||||
<< MacroName;
|
||||
}
|
||||
|
||||
Builder.defineMacro(MacroName, MacroBody.substr(0, End));
|
||||
} else {
|
||||
// Push "macroname 1".
|
||||
|
@ -490,7 +487,7 @@ void clang::InitializePreprocessor(Preprocessor &PP,
|
|||
Builder.undefineMacro(InitOpts.Macros[i].first);
|
||||
else
|
||||
DefineBuiltinMacro(Builder, InitOpts.Macros[i].first,
|
||||
&PP.getDiagnostics());
|
||||
PP.getDiagnostics());
|
||||
}
|
||||
|
||||
// If -imacros are specified, include them now. These are processed before
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
// RUN: %clang_cc1 -DA= -DB=1 -verify -fsyntax-only %s
|
||||
|
||||
int a[(B A) == 1 ? 1 : -1];
|
||||
|
Загрузка…
Ссылка в новой задаче