[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)

Julian Schmidt via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 23 11:04:48 PST 2024


5chmidti wrote:

> but now templates seem to be skipped completely

Template instantiations are skipped, not their definition. The matchers no longer work, because the types you are working with are no longer necessarily concrete types, but instead they can be dependent. And so can be expressions. 

In addition to the matchers for non-dependent code, you need to add matchers for the dependent case. See godbolt link I had linked: https://godbolt.org/z/GrfMTxeGa
and the included matcher (example, not full matcher):

```
callExpr(                            // no longer a CXXMemberCallExpr
    callee(
        cxxDependentScopeMemberExpr( // the callee is now a dependent member
            hasMemberName("subspan"),
            hasObjectExpression(
                hasType(             // this part is effectively HasSpanType but for a dependent type of `std::span<T>`
                    elaboratedType(
                        namesType(
                            qualType(
                                hasCanonicalType(
                                    qualType(
                                        hasDeclaration(
                                            namedDecl(hasName("::std::span"))
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )
)
```

https://github.com/llvm/llvm-project/pull/118074


More information about the cfe-commits mailing list