Skip to content
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

[Clang][Sema] Bump the instantiated index when skipping past non-init-captures #110887

Merged
merged 1 commit into from
Oct 3, 2024

Conversation

zyn0217
Copy link
Contributor

@zyn0217 zyn0217 commented Oct 2, 2024

Otherwise, we would probably have an unmatched instantiated declaration for init-captures when they come after a non-init capture.

No release note because the bug only affects the trunk so far.

Fixes #110721

…-captures

Otherwise, we would probably have an unmatched instantiated declaration
for init-captures when they come after a non-init capture.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Oct 2, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Oct 2, 2024

@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)

Changes

Otherwise, we would probably have an unmatched instantiated declaration for init-captures when they come after a non-init capture.

No release note because the bug only affects the trunk so far.

Fixes #110721


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

2 Files Affected:

  • (modified) clang/lib/Sema/SemaConcept.cpp (+1)
  • (modified) clang/test/SemaTemplate/concepts-lambda.cpp (+15)
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 6a1b32598bb4a6..41ca372743d2a5 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -728,6 +728,7 @@ bool Sema::addInstantiatedCapturesToScope(
     ValueDecl *CapturedPattern = CapturePattern.getCapturedVar();
 
     if (!CapturedPattern->isInitCapture()) {
+      Instantiated++;
       continue;
     }
 
diff --git a/clang/test/SemaTemplate/concepts-lambda.cpp b/clang/test/SemaTemplate/concepts-lambda.cpp
index 9c5807bbabdcbf..829a71bc703feb 100644
--- a/clang/test/SemaTemplate/concepts-lambda.cpp
+++ b/clang/test/SemaTemplate/concepts-lambda.cpp
@@ -279,3 +279,18 @@ void dependent_capture_packs() {
   L(V<0>{}, V<1>{}, V<2>{})(V<3>{}, V<4>{})(1);
 }
 } // namespace init_captures
+
+namespace GH110721 {
+
+template <int N> void connect() {
+  int x = N, y = N;
+  [x, y = y]()
+    requires requires { x; }
+  {}();
+}
+
+void foo() {
+  connect<42>();
+}
+
+} // namespace GH110721

@zyn0217 zyn0217 merged commit 5064c4c into llvm:main Oct 3, 2024
11 checks passed
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Assertion `CapturedVar->isInitCapture()' failed
3 participants