Skip to content

Commit

Permalink
[Clang] Retain the angle loci for invented template parameters of con…
Browse files Browse the repository at this point in the history
…straints (llvm#92104)

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

Fixes clangd/clangd#2033
  • Loading branch information
zyn0217 authored May 14, 2024
1 parent d9db266 commit 8070b2d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions clang-tools-extra/clangd/unittests/SelectionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
13 changes: 13 additions & 0 deletions clang/test/AST/ast-dump-concepts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

}

0 comments on commit 8070b2d

Please sign in to comment.