[clang-tools-extra] 8070b2d - [Clang] Retain the angle loci for invented template parameters of constraints (#92104)
via cfe-commits
cfe-commits at lists.llvm.org
Tue May 14 07:44:05 PDT 2024
Author: Younan Zhang
Date: 2024-05-14T22:44:01+08:00
New Revision: 8070b2defa6df1f1a3f3d4ed4989047b0e1bb639
URL: https://github.com/llvm/llvm-project/commit/8070b2defa6df1f1a3f3d4ed4989047b0e1bb639
DIFF: https://github.com/llvm/llvm-project/commit/8070b2defa6df1f1a3f3d4ed4989047b0e1bb639.diff
LOG: [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
Added:
Modified:
clang-tools-extra/clangd/unittests/SelectionTests.cpp
clang/lib/Sema/SemaType.cpp
clang/test/AST/ast-dump-concepts.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/unittests/SelectionTests.cpp b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
index db516a1f62a35..aaaf758e72236 100644
--- a/clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -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) {
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index d65fafc8cf4f7..eb67546d048ae 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -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(),
diff --git a/clang/test/AST/ast-dump-concepts.cpp b/clang/test/AST/ast-dump-concepts.cpp
index 5bb174e3548ed..a5e0673c241ef 100644
--- a/clang/test/AST/ast-dump-concepts.cpp
+++ b/clang/test/AST/ast-dump-concepts.cpp
@@ -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>
+
+}
More information about the cfe-commits
mailing list