[PATCH] D73775: [clang-tidy] Cover cases like (b && c && b) in the redundant expression check

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 12 11:38:36 PST 2020


aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM aside from a minor nit.



================
Comment at: clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp:355
+           collectOperands<TExpr>(Operands.second, AllOperands, OpKind);
+  } else {
+    AllOperands.push_back(Part);
----------------
No `else` after a `return`.


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp:206
+
+  if (U && V && U && V) return true;
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: overloaded operator has equivalent nested operands
----------------
I think that this is reasonable behavior, however, once the user overloads the operator there's no way to know whether calling that operator has other side effects that make this not actually be equivalent to `U && V`. That said, unless this happens an awful lot in practice, this still seems like a reasonable heuristic.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73775/new/

https://reviews.llvm.org/D73775





More information about the cfe-commits mailing list