Skip to content

Commit 8070b2d

Browse files
authored
[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 clangd/clangd#2033
1 parent d9db266 commit 8070b2d

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

clang-tools-extra/clangd/unittests/SelectionTests.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,12 @@ TEST(SelectionTest, CommonAncestor) {
589589
auto x = [[ns::^C<int>]];
590590
)cpp",
591591
"ConceptReference"},
592+
{R"cpp(
593+
template <typename T, typename K>
594+
concept D = true;
595+
template <typename T> void g(D<[[^T]]> auto abc) {}
596+
)cpp",
597+
"TemplateTypeParmTypeLoc"},
592598
};
593599

594600
for (const Case &C : Cases) {

clang/lib/Sema/SemaType.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3099,7 +3099,8 @@ InventTemplateParameter(TypeProcessingState &state, QualType T,
30993099
// The 'auto' appears in the decl-specifiers; we've not finished forming
31003100
// TypeSourceInfo for it yet.
31013101
TemplateIdAnnotation *TemplateId = D.getDeclSpec().getRepAsTemplateId();
3102-
TemplateArgumentListInfo TemplateArgsInfo;
3102+
TemplateArgumentListInfo TemplateArgsInfo(TemplateId->LAngleLoc,
3103+
TemplateId->RAngleLoc);
31033104
bool Invalid = false;
31043105
if (TemplateId->LAngleLoc.isValid()) {
31053106
ASTTemplateArgsPtr TemplateArgsPtr(TemplateId->getTemplateArgs(),

clang/test/AST/ast-dump-concepts.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,16 @@ auto FooFunc(C auto V) -> C decltype(auto) {
107107
}
108108

109109
}
110+
111+
namespace constraint_auto_params {
112+
113+
template <class T, class K>
114+
concept C = true;
115+
116+
template<class T>
117+
void g(C<T> auto Foo) {}
118+
119+
// CHECK: TemplateTypeParmDecl {{.*}} depth 0 index 1 Foo:auto
120+
// CHECK-NEXT: `-ConceptSpecializationExpr {{.*}} <col:8, col:11>
121+
122+
}

0 commit comments

Comments
 (0)