[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
Fri Dec 6 14:22:52 PST 2024


https://github.com/5chmidti commented:

> wasting effort would not be the problem (it never is; learning is the goal) - right now i just dont understand the difference, and therefore dont see the benefit, as far as i see it would introduce more complicated code to still handle templates.

`TK_IgnoreUnlessSpelledInSource` changes how the AST is seen by excluding AST nodes that are implicit, e.g., implicit template instantiations or implicit casts. This can in some cases improve the readability of the check by simplifying the matcher, or improve performance because not every implicit AST node, such as instantiated templates, are traversed and checked. The effect of this varies a lot, depending on what a check is trying to achieve. Checkout the [Traverse Mode](https://clang.llvm.org/docs/LibASTMatchersReference.html#:~:text=Traverse%20Mode) section on top of the AST matcher reference for more details, and importantly, a lot of examples on the differences.

For this check, the benefit will be performance, and not readability. It will be possible to skip template instantiations, of which there may be many because `span` is *the* generic view on contiguous memory (joined by `mdspan`). Overall, the checking done by this check is not too costly, so there would not be a massive difference.

Godbolt with the AST view and clang-query are great to iteratively build up a matcher, checkout https://godbolt.org/z/GrfMTxeGa for matching uninstantiated templates with `TK_IgnoreUnlessSpelledInSource`

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


More information about the cfe-commits mailing list