Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 14, 2024

Conversation

zyn0217
Copy link
Contributor

@zyn0217 zyn0217 commented May 14, 2024

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

Fixes clangd/clangd#2033

…straints

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

Fixes clangd/clangd#2033
@zyn0217 zyn0217 added clangd clang:frontend Language frontend issues, e.g. anything involving "Sema" labels May 14, 2024
@llvmbot llvmbot added clang Clang issues not falling into any other category clang-tools-extra labels May 14, 2024
@llvmbot
Copy link
Member

llvmbot commented May 14, 2024

@llvm/pr-subscribers-clang
@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clangd

Author: Younan Zhang (zyn0217)

Changes

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

Fixes clangd/clangd#2033


Full diff: https://github.com/llvm/llvm-project/pull/92104.diff

3 Files Affected:

  • (modified) clang-tools-extra/clangd/unittests/SelectionTests.cpp (+5)
  • (modified) clang/lib/Sema/SemaType.cpp (+2-1)
  • (modified) clang/test/AST/ast-dump-concepts.cpp (+13)
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>
+
+}

Copy link

github-actions bot commented May 14, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Collaborator

@hokein hokein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@zyn0217
Copy link
Contributor Author

zyn0217 commented May 14, 2024

Thanks for the review!

The Linux CI is green, so I presume so is the sluggish Windows CI. Landing it now.

@zyn0217 zyn0217 merged commit 8070b2d into llvm:main May 14, 2024
3 of 4 checks passed
@zyn0217 zyn0217 deleted the issue-2033 branch May 14, 2024 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category clang-tools-extra clangd
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Template arguments in placeholder's type-constraint are not selected correctly.
3 participants