[clang] [clang][StaticAnalyzer] Add enclosing Decl information to bug reports of RawPtrRef(LocalVars|Member)Checker (PR #214102)

Balázs Benics via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 6 01:59:00 PDT 2026


================

----------------
steakhal wrote:

Why is this function implemented using this switch?
It's perplexing to me because switch on kinds doesn't respect subtyping (is-a) relations. What makes this even more confusing is that we already have a subtyping honoring dyn_cast to NamedDecl so the author must have known this.

Naively I'd write this as:
```
if (D is a FunctionDecl)
  return GetSignature(D);

if (D is a NamedDecl)
  return D->getQualifiedNameAsString();
return "";
```

So my question is, why did the original author choose the more complicated, more brittle solution in the presence of dyn_cast to ND? To me, this would solve this once and for all, regardless of what Decl kinds appear in the future.

---

Maybe I shouldn't overthink this because the `dyn_cast_or_null<FunctionDecl>(ND)` suggests that the author might not have fully thought this through. ND can never be null there, and ND always satisfies the cast and should have been using `cast` instead.

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


More information about the cfe-commits mailing list