[PATCH] Fix for llvm.org/PR23161
Szabolcs Sipos
szabolcs.sipos at ericsson.com
Thu May 7 07:43:57 PDT 2015
Hi alexfh,
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.
http://reviews.llvm.org/D9561
Files:
clang-tidy/misc/StaticAssertCheck.cpp
test/clang-tidy/misc-static-assert.cpp
Index: clang-tidy/misc/StaticAssertCheck.cpp
===================================================================
--- clang-tidy/misc/StaticAssertCheck.cpp
+++ clang-tidy/misc/StaticAssertCheck.cpp
@@ -29,7 +29,7 @@
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(
Index: test/clang-tidy/misc-static-assert.cpp
===================================================================
--- test/clang-tidy/misc-static-assert.cpp
+++ test/clang-tidy/misc-static-assert.cpp
@@ -95,6 +95,12 @@
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!");
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9561.25183.patch
Type: text/x-patch
Size: 1380 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150507/a2ce9137/attachment.bin>
More information about the cfe-commits
mailing list