[clang-tidy] Fix for llvm.org/PR23161

The misc-static-assert check will not warn on the followings:
    assert(NULL == "shouldn't warn");
    assert(__null == "shouldn't warn");

Where NULL is a macro defined as __null.

llvm-svn: 236812
This commit is contained in:
Szabolcs Sipos 2015-05-08 07:56:24 +00:00
parent 69694b0691
commit 60ce8bb0be
2 changed files with 7 additions and 1 deletions

View File

@ -29,7 +29,7 @@ StaticAssertCheck::StaticAssertCheck(StringRef Name, ClangTidyContext *Context)
void StaticAssertCheck::registerMatchers(MatchFinder *Finder) {
auto IsAlwaysFalse = expr(ignoringParenImpCasts(
expr(anyOf(boolLiteral(equals(false)), integerLiteral(equals(0)),
nullPtrLiteralExpr())).bind("isAlwaysFalse")));
nullPtrLiteralExpr(), gnuNullExpr())).bind("isAlwaysFalse")));
auto IsAlwaysFalseWithCast = ignoringParenImpCasts(anyOf(IsAlwaysFalse,
cStyleCastExpr(has(IsAlwaysFalse)).bind("castExpr")));
auto AssertExprRoot = anyOf(

View File

@ -95,6 +95,12 @@ int main() {
assert(NULL && "Report me!");
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be
// CHECK-FIXES: {{^ }}static_assert(NULL , "Report me!");
#define NULL __null
assert(__null == "Don't report me!");
// CHECK-FIXES: {{^ }}assert(__null == "Don't report me!");
assert(NULL == "Don't report me!");
// CHECK-FIXES: {{^ }}assert(NULL == "Don't report me!");
#undef NULL
assert(ZERO_MACRO && "Report me!");