[clang] [ASTMatchers] Extend hasName matcher when matching templates (PR #100349)
Julian Schmidt via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 24 06:55:21 PDT 2024
================
@@ -653,10 +686,12 @@ bool HasNameMatcher::matchesNodeFullSlow(const NamedDecl &Node) const {
for (const StringRef Pattern : Names) {
if (Pattern.starts_with("::")) {
- if (FullName == Pattern)
+ if (auto Result = consumePatternBack(Pattern, FullName);
+ Result && Result->empty()) {
return true;
- } else if (FullName.ends_with(Pattern) &&
- FullName.drop_back(Pattern.size()).ends_with("::")) {
+ }
+ } else if (auto Result = consumePatternBack(Pattern, FullName);
+ Result && Result->ends_with("::")) {
return true;
}
----------------
5chmidti wrote:
You could write this loop body as
```c++
const std::optional<StringRef> Result =
consumePatternBack(Pattern, FullName);
if (!Result)
continue;
if ((Pattern.starts_with("::") && Result->empty()) ||
Result->ends_with("::"))
return true;
```
which is more readable IMO
https://github.com/llvm/llvm-project/pull/100349
More information about the cfe-commits
mailing list