[clang] [webkit.NoUncountedMemberChecker] Warn a raw pointer member in a template instantiation (PR #240100)

Ryosuke Niwa via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 8 09:48:40 PST 2026


rniwa wrote:

`getPointOfInstantiation` returns a `SourceLocation`, not a declaration. To call it again, we need the declaration that caused the instantiation, which for `Inner<RC>` is `Middle<RC>`. The AST has no lookup from a location back to the declaration that contains it. Building one means another side table, which is what we want to avoid.

That location is shared by every instantiation of the enclosing template. Suppose we did find the declaration at `Inner<RC>`'s point of instantiation (t.cpp:3:48, the `Inner<T> inner`; field). That field belongs to the pattern `Middle<T>`, not to `Middle<RC>`. Every instantiation of Middle has its members at those same pattern locations, so `Inner<int>` from a `Middle<int>` would also report 3:48. The location doesn't say which `Middle` specialization was involved, and that specialization's own point of instantiation is the next step up the chain.

We could pick the right one by going through every specialization of the enclosing template and checking which one has a field or base of type `Inner<RC>`. That only works for fields and bases; the function-template case (`callUseInner<UF>` → `useInner<UF>` → `local Inner<UF>`) would mean scanning function bodies. That seems more complicated than having a map in the current PR.

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


More information about the cfe-commits mailing list