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) {
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);
}
//===----------------------------------------------------------------------===//
// 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);
"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,
--- /dev/null
+// 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
+