mizvekov wrote:

> Thanks for the feedback @mizvekov. I propose this change for the following 
> reasons:
> 
> * Class template implicit instantiations have technically no source range 
> anywhere, which is why I think having the same behavior as function template 
> implicit instantiations or variable template implicit instantiations is the 
> best approach.
> * It is also the behavior of other implicit code like special member 
> functions, that are located at the class definition and not at the latest 
> declaration.
> * Class template implicit instantiations are definitions: calling 
> `isThisDeclarationADefinition()` on them will return true, so one would 
> expect their range to actually contain a definition.
> * Calling `ClassTemplateSpecializationDecl::getLocation()` returns the 
> location of the definition already, so there is also a difference of behavior 
> between `getLocation()` and `getSourceRange()` that I find confusing.

Yes, as you point out, template instantiations don't have source locations, as 
they are not things written by the user. It would make sense to ask what is the 
source location of the thing it was instantiated from, but that's also 
confusing when you have multiple declarations.

So I don't think clang has a principled stand here, and I'd like to come up 
with something that would decide this is the right approach, so if someone in a 
couple of months comes up with a patch changing everything to the opposite 
direction, we would be able to decide which is right.

So, what makes this direction seem right to you, why would you even want to ask 
the source locations of these things, and expect there to be a single answer? 
Or are you purely concerned about the lack of consistency, and would like a 
single answer everywhere, regardless of what approach?

If we stopped storing source locations on these things, and stop giving you a 
single answer, but you would still be able to query what declaration it was 
instantiated from, and you could decide for yourself which redeclaration to 
obtain this answer from, would that be okay?

https://github.com/llvm/llvm-project/pull/156011
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to