This allows for matching the constructors std::string has in common with
std::string_view.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp | ||
---|---|---|
58 | You should fix the lint warning. | |
59 | 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. |
clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp | ||
---|---|---|
29–33 | hasAnyName is a VariadicMatcher, so it supports passing a list directly (as a single argument), see ASTMatchersInternal.h, line 103. Given that, I'm pretty sure this function is unnecessary; you can just call hasAnyName directly below instead of this function. | |
103–104 | Following up on Aaron's comment above, I think you want something like this: hasDeclaration(cxxConstructorDecl(ofClass(cxxRecordDecl(hasAnyName(removeNamespaces(StringNames)))) | |
128 | nit: I'd put this comment line before the anyOf since it describes the whole thing, while the following comments describe each branch, respectively. |
Applied review comments
clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp | ||
---|---|---|
59 | I applied ymandel's suggestion, which I think simplified things a bit. |
hasAnyName is a VariadicMatcher, so it supports passing a list directly (as a single argument), see ASTMatchersInternal.h, line 103.
Given that, I'm pretty sure this function is unnecessary; you can just call hasAnyName directly below instead of this function.