[PATCH] [clang-tidy] Fix for Bug 23161
Szabolcs Sipos
szabolcs.sipos at ericsson.com
Thu Apr 9 06:32:50 PDT 2015
Hi alexfh,
The misc-static-assert check will not warn on the followings:
- assert("Some message" == NULL);
- assert(NULL == "Some message");
Added corresponding test cases.
[[ https://llvm.org/bugs/show_bug.cgi?id=23161 | Bug 23161 ]]
http://reviews.llvm.org/D8920
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,10 +29,11 @@
void StaticAssertCheck::registerMatchers(MatchFinder *Finder) {
auto IsAlwaysFalse = ignoringParenImpCasts(
anyOf(boolLiteral(equals(false)).bind("isAlwaysFalse"),
- integerLiteral(equals(0)).bind("isAlwaysFalse")));
+ integerLiteral(equals(0)).bind("isAlwaysFalse"),
+ nullPtrLiteralExpr().bind("isAlwaysFalse")));
auto AssertExprRoot = anyOf(
binaryOperator(
- hasOperatorName("&&"),
+ anyOf(hasOperatorName("&&"), hasOperatorName("==")),
hasEitherOperand(ignoringImpCasts(stringLiteral().bind("assertMSG"))),
anyOf(binaryOperator(hasEitherOperand(IsAlwaysFalse)), anything()))
.bind("assertExprRoot"),
@@ -83,7 +84,8 @@
StringRef FalseMacroName =
Lexer::getImmediateMacroName(FalseLiteralLoc, SM, Opts);
- if (FalseMacroName.compare_lower("false") == 0)
+ if (FalseMacroName.compare_lower("false") == 0 ||
+ FalseMacroName.compare_lower("null") == 0)
return;
}
Index: test/clang-tidy/misc-static-assert.cpp
===================================================================
--- test/clang-tidy/misc-static-assert.cpp
+++ test/clang-tidy/misc-static-assert.cpp
@@ -15,6 +15,8 @@
#define False false
#define FALSE 0
+#define NULL 0
+
#define my_macro() assert(0 == 1)
// CHECK-FIXES: #define my_macro() assert(0 == 1)
@@ -78,6 +80,18 @@
assert(false && "Don't report me!");
// CHECK-FIXES: {{^ }}assert(false && "Don't report me!");
+ 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!");
+
+ assert("Don't report me!" == NULL);
+ // CHECK-FIXES: {{^ }}assert("Don't report me!" == NULL);
+
+ assert(0 == "Don't report me!");
+ // CHECK-FIXES: {{^ }}assert(0 == "Don't report me!");
+
assert(ZERO_MACRO && "Report me!");
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be
// CHECK-FIXES: {{^ }}static_assert(ZERO_MACRO , "Report me!");
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8920.23484.patch
Type: text/x-patch
Size: 2304 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150409/0ddbc6da/attachment.bin>
More information about the cfe-commits
mailing list