[PATCH] D21185: [clang-tidy] Add performance-emplace-into-containers

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 22 06:19:02 PDT 2016


aaron.ballman added inline comments.

================
Comment at: clang-tidy/performance/EmplaceCheck.cpp:26
@@ +25,3 @@
+          on(expr(hasType(cxxRecordDecl(hasName("std::vector"))))),
+          callee(functionDecl(hasName("push_back"))),
+          hasArgument(0, cxxConstructExpr().bind("construct_expr")))
----------------
sbenza wrote:
> Just say functionDecl(hasName("std::vector::push_back")) and you can remove the type check.
Should use "::std::vector::push_back" just to be sure it doesn't explode when evil people have:
```
namespace frobble {
namespace std {
template <typename T>
class vector {
  void push_back(const T&);
};
}
}
```

================
Comment at: clang-tidy/performance/EmplaceCheck.cpp:38
@@ +37,3 @@
+  if (SR.isInvalid())
+    return {};
+  return Lexer::getSourceText(Lexer::getAsCharRange(SR, SM, LO), SM, LO);
----------------
I think this goes against our coding standards and should be `return StringRef();`.


http://reviews.llvm.org/D21185





More information about the cfe-commits mailing list