[PATCH] D91015: [clang-tidy] Extend bugprone-string-constructor-check to std::string_view.

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 9 06:58:09 PST 2020


aaron.ballman added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp:64
 void StringConstructorCheck::registerMatchers(MatchFinder *Finder) {
+  const auto hasStringCtorName =
+      hasAnyNameStdString(removeNamespaces(StringNames));
----------------
You should fix the lint warning.


================
Comment at: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp:65
+  const auto hasStringCtorName =
+      hasAnyNameStdString(removeNamespaces(StringNames));
+
----------------
It took me a while to realize that this functionality is really about trying to get to the name of the constructor for a given type -- perhaps this should be a single function called `getCtorNameFromType()` or something?

Actually, given that this is a narrowing matcher from a `CXXConstructExpr`, can't you look at `CXXConstructExpr::getConstructor()` to get the `CXXConstructorDecl` and check the name from there? That seems cleaner than trying to identify the constructor name through string matching.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91015



More information about the cfe-commits mailing list