Open carlosgalvezp opened 1 month ago
@llvm/issue-subscribers-clang-tidy
Author: Carlos Galvez (carlosgalvezp)
See #73270 for an example. That ticket is closed since it also contained a false positive but the actual issue I posted it for was not fixed. I haven't gotten around to opening it again but this new ticket will do now.
That example actually shows the issue in a self-contained file. So it does not just happen with shared code.
Sounds like a good idea, the reason why and where something happened is not always evident from the diagnostic alone.
I believe in Clang this is achieved by Sema::PrintInstantiationStack()
. I'm not sure if/how it would be possible to re-use or port that over to clang-tidy. @AaronBallman do you have some insights or pointers that we could look into? Do you think this is a solvable problem?
I don't think it's solvable in the short-term; in the long term, we may be able to get there. The problem is that we need semantic information to print the correct instantiation stack and clang-tidy purposefully has no access to Sema
because tidy is expected to work on completed ASTs. I don't think we want to expose all of Sema
because that's ripe for accidental misuse (it's pretty tightly coupled with expectations from the parser and so it's easy to hit assertions or other misbehaviors), but I think we may eventually need to expose some amount of Sema
because of the C++ reflection feature (where evaluating a constant expression may have side effects that include introducing new AST nodes which require semantic analysis). However, how that works is very much an open question we don't have answers for.
Often times we have core, templated library functions that are used across the project. Sometimes these functions are used incorrectly by the clients, leading to clang-tidy warnings in the library code. It is however not possible to quickly pinpoint where in the client code the mistakes were made.
This could be solved by printing the instantiation stack of where the error comes from, similar to how it's done for Clang compiler errors.
I opened a discussion here, with no comments so far: https://discourse.llvm.org/t/print-template-instantiation-stack-on-warnings/81046