[PATCH] D33827: [clang-tidy] misc-static-assert shouldn't flag assert(!"msg")
Florian Gross via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 2 06:20:17 PDT 2017
fgross created this revision.
Herald added a subscriber: xazax.hun.
Added negated string literals to the set of IsAlwaysFalse expressions to avoid flagging of
assert(!"msg")
https://reviews.llvm.org/D33827
Files:
clang-tidy/misc/StaticAssertCheck.cpp
test/clang-tidy/misc-static-assert.cpp
Index: test/clang-tidy/misc-static-assert.cpp
===================================================================
--- test/clang-tidy/misc-static-assert.cpp
+++ test/clang-tidy/misc-static-assert.cpp
@@ -76,6 +76,9 @@
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be
// CHECK-FIXES: {{^ }}static_assert(ZERO_MACRO, "");
+ assert(!"Don't report me!");
+ // CHECK-FIXES: {{^ }}assert(!"Don't report me!");
+
assert(0 && "Don't report me!");
// CHECK-FIXES: {{^ }}assert(0 && "Don't report me!");
Index: clang-tidy/misc/StaticAssertCheck.cpp
===================================================================
--- clang-tidy/misc/StaticAssertCheck.cpp
+++ clang-tidy/misc/StaticAssertCheck.cpp
@@ -33,9 +33,11 @@
if (!(getLangOpts().CPlusPlus11 || getLangOpts().C11))
return;
+ auto NegatedString = unaryOperator(
+ hasOperatorName("!"), hasUnaryOperand(ignoringImpCasts(stringLiteral())));
auto IsAlwaysFalse =
expr(anyOf(cxxBoolLiteral(equals(false)), integerLiteral(equals(0)),
- cxxNullPtrLiteralExpr(), gnuNullExpr()))
+ cxxNullPtrLiteralExpr(), gnuNullExpr(), NegatedString))
.bind("isAlwaysFalse");
auto IsAlwaysFalseWithCast = ignoringParenImpCasts(anyOf(
IsAlwaysFalse, cStyleCastExpr(has(ignoringParenImpCasts(IsAlwaysFalse)))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33827.101197.patch
Type: text/x-patch
Size: 1358 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170602/32a41538/attachment-0001.bin>
More information about the cfe-commits
mailing list