[clang-tools-extra] [llvm] [clang] [Clang][Sema] Don't say "is declared here" for invalid template locations (PR #71264)

Justin Bogner via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 29 22:44:05 PST 2023


bogner wrote:

> I agree that "is declared here" is useless when "here" is... nowhere. But the point to the note is to help the user to see what the actual declaration is to help them repair the issue. Losing the note entirely isn't the worst thing, but I wonder if it would be better for declarations coming from external AST sources to pretty print the declaration instead? e.g., Before:
> 
> ```
> hlsl::vector<1> BadVec; // expected-error{{template argument for template type parameter must be a type}}
> // expected-note@*:* {{template is declared here}}
> // expected-note@*:* {{template parameter is declared here}}
> ```
> 
> After:
> 
> ```
> hlsl::vector<1> BadVec; // expected-error{{template argument for template type parameter must be a type}}
> // expected-note at -1 {{template declaration from hidden source: template <typename Ty> vector}}
> // expected-note at -2 {{template parameter from hidden source: typename Ty}}
> ```
> 
> This would give the user more relevant information than just dropping the notes. (I have no idea if I'm asking for something incredibly difficult but I was thinking we could use the declaration printer to print this information out to the diagnostic in these cases.)

I made an attempt at this, and I think I like it. It does have a bit of novelty in terms of how it generates appropriate errors though.

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


More information about the cfe-commits mailing list