https://github.com/zyn0217 updated https://github.com/llvm/llvm-project/pull/92104
>From d9c0121067162ffb68bc70b9a0a3f10e0b05674c Mon Sep 17 00:00:00 2001 From: Younan Zhang <zyn7...@gmail.com> Date: Tue, 14 May 2024 19:46:20 +0800 Subject: [PATCH 1/2] [Clang] Retain the angle loci for invented template parameters of constraints Clangd uses it to determine whether the argument is within the selection range. Fixes https://github.com/clangd/clangd/issues/2033 --- .../clangd/unittests/SelectionTests.cpp | 5 +++++ clang/lib/Sema/SemaType.cpp | 3 ++- clang/test/AST/ast-dump-concepts.cpp | 13 +++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/unittests/SelectionTests.cpp b/clang-tools-extra/clangd/unittests/SelectionTests.cpp index db516a1f62a35..706286e22cf74 100644 --- a/clang-tools-extra/clangd/unittests/SelectionTests.cpp +++ b/clang-tools-extra/clangd/unittests/SelectionTests.cpp @@ -589,6 +589,11 @@ 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 fddc3545ecb61..7eb7cda63a61f 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -3516,7 +3516,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> + +} >From 15a320c21ad25676cb75a1b622405c440d93c313 Mon Sep 17 00:00:00 2001 From: Younan Zhang <zyn7...@gmail.com> Date: Tue, 14 May 2024 19:56:19 +0800 Subject: [PATCH 2/2] Run clang-format --- clang-tools-extra/clangd/unittests/SelectionTests.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/unittests/SelectionTests.cpp b/clang-tools-extra/clangd/unittests/SelectionTests.cpp index 706286e22cf74..aaaf758e72236 100644 --- a/clang-tools-extra/clangd/unittests/SelectionTests.cpp +++ b/clang-tools-extra/clangd/unittests/SelectionTests.cpp @@ -593,7 +593,8 @@ TEST(SelectionTest, CommonAncestor) { template <typename T, typename K> concept D = true; template <typename T> void g(D<[[^T]]> auto abc) {} - )cpp", "TemplateTypeParmTypeLoc"}, + )cpp", + "TemplateTypeParmTypeLoc"}, }; for (const Case &C : Cases) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits