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

----------------
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
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to