[Clang] Retain the angle loci for invented template parameters of constraints (#92104)

Clangd uses it to determine whether the argument is within the selection
range.

Fixes https://github.com/clangd/clangd/issues/2033
This commit is contained in:
Younan Zhang 2024-05-14 22:44:01 +08:00 committed by GitHub
parent d9db266499
commit 8070b2defa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 1 deletions

View File

@ -589,6 +589,12 @@ TEST(SelectionTest, CommonAncestor) {
auto x = [[ns::^C<int>]];
)cpp",
"ConceptReference"},
{R"cpp(
template <typename T, typename K>
concept D = true;
template <typename T> void g(D<[[^T]]> auto abc) {}
)cpp",
"TemplateTypeParmTypeLoc"},
};
for (const Case &C : Cases) {

View File

@ -3099,7 +3099,8 @@ InventTemplateParameter(TypeProcessingState &state, QualType T,
// The 'auto' appears in the decl-specifiers; we've not finished forming
// TypeSourceInfo for it yet.
TemplateIdAnnotation *TemplateId = D.getDeclSpec().getRepAsTemplateId();
TemplateArgumentListInfo TemplateArgsInfo;
TemplateArgumentListInfo TemplateArgsInfo(TemplateId->LAngleLoc,
TemplateId->RAngleLoc);
bool Invalid = false;
if (TemplateId->LAngleLoc.isValid()) {
ASTTemplateArgsPtr TemplateArgsPtr(TemplateId->getTemplateArgs(),

View File

@ -107,3 +107,16 @@ auto FooFunc(C auto V) -> C decltype(auto) {
}
}
namespace constraint_auto_params {
template <class T, class K>
concept C = true;
template<class T>
void g(C<T> auto Foo) {}
// CHECK: TemplateTypeParmDecl {{.*}} depth 0 index 1 Foo:auto
// CHECK-NEXT: `-ConceptSpecializationExpr {{.*}} <col:8, col:11>
}