[PATCH] D33209: [clang-tidy] Add "emplace_back" detection in inefficient-vector-operation.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 16 02:00:11 PDT 2017


hokein marked an inline comment as done.
hokein added inline comments.


================
Comment at: clang-tidy/performance/InefficientVectorOperationCheck.cpp:92
+  const auto VectorAppendCall = expr(
+      anyOf(VectorAppendCallExpr, exprWithCleanups(has(VectorAppendCallExpr))));
   const auto VectorVarDefStmt =
----------------
malcolm.parsons wrote:
> I'd use ignoringImplicit(VectorAppendCallExpr) to ignore ExprWithCleanups.
Good to know. Thanks!


================
Comment at: clang-tidy/performance/InefficientVectorOperationCheck.cpp:208
+           "consider pre-allocating the vector capacity before the loop")
+      << VectorAppendCall->getMethodDecl()->getDeclName();
 
----------------
alexfh wrote:
> Diagnostic builder should be able to format NamedDecls directly, this `->getDeclName()` is not necessary. The only difference is that it will likely add quotes around the name, which seems to be good anyway.
I tried it, but I found the behavior between using `getDeclName()` and not using `getDeclName()` is different when handling the template functions:

* `diag(...) << VectorAppendCall->getMethodDecl()` will print the function name with instantiated template arguments like "emplace_back<int&>";
*  `diag(...) << VectorAppendCall->getMethodDecl()->getDeclName()` will just print the function name without template arguments, which is what we expect.


https://reviews.llvm.org/D33209





More information about the cfe-commits mailing list