зеркало из https://github.com/microsoft/clang.git
add support for -Wundef.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46274 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
269b10d493
Коммит
116a4b148e
|
@ -404,6 +404,11 @@ static llvm::cl::opt<bool>
|
|||
WarnNoFormatNonLiteral("Wno-format-nonliteral",
|
||||
llvm::cl::desc("Do not warn about non-literal format strings."));
|
||||
|
||||
static llvm::cl::opt<bool>
|
||||
WarnUndefMacros("Wundef",
|
||||
llvm::cl::desc("Warn on use of undefined macros in #if's"));
|
||||
|
||||
|
||||
/// InitializeDiagnostics - Initialize the diagnostic object, based on the
|
||||
/// current command line option settings.
|
||||
static void InitializeDiagnostics(Diagnostic &Diags) {
|
||||
|
@ -423,7 +428,8 @@ static void InitializeDiagnostics(Diagnostic &Diags) {
|
|||
if (WarnNoFormatNonLiteral)
|
||||
Diags.setDiagnosticMapping(diag::warn_printf_not_string_constant,
|
||||
diag::MAP_IGNORE);
|
||||
|
||||
if (!WarnUndefMacros)
|
||||
Diags.setDiagnosticMapping(diag::warn_pp_undef_identifier,diag::MAP_IGNORE);
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
|
@ -74,6 +74,7 @@ static bool EvaluateValue(llvm::APSInt &Result, Token &PeekTok,
|
|||
// into a simple 0, unless it is the C++ keyword "true", in which case it
|
||||
// turns into "1".
|
||||
if (II->getPPKeywordID() != tok::pp_defined) {
|
||||
PP.Diag(PeekTok, diag::warn_pp_undef_identifier, II->getName());
|
||||
Result = II->getTokenID() == tok::kw_true;
|
||||
Result.setIsUnsigned(false); // "0" is signed intmax_t 0.
|
||||
PP.LexNonComment(PeekTok);
|
||||
|
|
|
@ -206,6 +206,8 @@ DIAG(err_pp_expected_rparen, ERROR,
|
|||
"expected ')' in preprocessor expression")
|
||||
DIAG(err_pp_expected_eol, ERROR,
|
||||
"expected end of line in preprocessor expression")
|
||||
DIAG(warn_pp_undef_identifier, WARNING,
|
||||
"\"%0\" is not defined, evaluates to 0")
|
||||
DIAG(err_pp_defined_requires_identifier, ERROR,
|
||||
"operator \"defined\" requires an identifier")
|
||||
DIAG(err_pp_missing_rparen, ERROR,
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
// RUN: clang %s -E -Wundef -Werror 2>&1 | grep error | count 1 &&
|
||||
// RUN: clang %s -E -Werror 2>&1 | not grep error
|
||||
|
||||
#if foo // Should generate an warning
|
||||
#endif
|
||||
|
||||
#ifdef foo
|
||||
#endif
|
||||
|
||||
#if defined(foo)
|
||||
#endif
|
||||
|
Загрузка…
Ссылка в новой задаче