[PATCH] D31542: [clang-tidy] Extend readability-container-size-empty to add comparisons to newly-constructed objects

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 15 06:31:28 PDT 2017


aaron.ballman added a comment.

> ... which has the wrong precedence; an extra set of parens is necessary.
>  However, I don't want to add a set of parens if it isn't necessary. ...

One way to handle this is to not suggest the fixit if the container part of the equality check is not a DeclRefExpr (perhaps after ignoring implicit casts, etc). This means the fixit won't get suggested in some cases where it otherwise could, such as:

  std::vector<std::string> v;
  if (v[0] == "") {
  }

but it does mean that it will still catch the common cases.



================
Comment at: clang-tidy/readability/ContainerSizeEmptyCheck.cpp:70
+      ignoringImpCasts(cxxBindTemporaryExpr(has(cxxConstructExpr(
+          hasDeclaration(cxxConstructorDecl(isDefaultConstructor())))))),
+      ignoringImplicit(cxxConstructExpr(
----------------
You should pull the `cxxConstructExpr(hasDeclaration(cxxConstructorDecl(isDefaultConstructor())))` into a separate variable and reuse it instead of spelling it out four times.


Repository:
  rL LLVM

https://reviews.llvm.org/D31542





More information about the cfe-commits mailing list