[PATCH] [clang-tidy] Assert related checkers

Richard legalize at xmission.com
Sat Feb 14 17:02:08 PST 2015


================
Comment at: clang-tidy/misc/AssertSideEffectCheck.cpp:46-53
@@ +45,10 @@
+    if (OpCallExpr) {
+      OverloadedOperatorKind OpKind = OpCallExpr->getOperator();
+      return OpKind == OO_Equal || OpKind == OO_PlusEqual ||
+             OpKind == OO_MinusEqual || OpKind == OO_StarEqual ||
+             OpKind == OO_SlashEqual || OpKind == OO_SlashEqual ||
+             OpKind == OO_PipeEqual || OpKind == OO_CaretEqual ||
+             OpKind == OO_LessLessEqual || OpKind == OO_GreaterGreaterEqual ||
+             OpKind == OO_PlusPlus || OpKind == OO_MinusMinus ||
+             OpKind == OO_PercentEqual;
+    }
----------------
What about `OO_AmpEqual`?

================
Comment at: test/clang-tidy/misc-assert-side-effect.cpp:42-62
@@ +41,23 @@
+
+int main() {
+
+  int X = 0;
+  assert(X == 1);
+
+  assert(X = 1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect [misc-assert-side-effect]
+  my_assert(X = 1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found my_assert() with side effect
+  not_my_assert(X = 1);
+
+  MyClass mc;
+  assert(mc.badFunc(0, 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+  assert(mc.goodFunc(0, 1));
+
+  MyClass mc2;
+  assert(mc2 = mc);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+
+  return 0;
+}
----------------
Most of the items detected have no test cases.  I used the `FileCheck` tests to push my implementation forward ensuring that I always had some test case for all the combinations.  The test cases can also serve as good executable documentation for everything the check does.

http://reviews.llvm.org/D7375

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list