[clang] [Clang][Sema] Bump the instantiated index when skipping past non-init-captures (PR #110887)
    via cfe-commits 
    cfe-commits at lists.llvm.org
       
    Wed Oct  2 09:59:28 PDT 2024
    
    
  
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Younan Zhang (zyn0217)
<details>
<summary>Changes</summary>
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
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/110887
    
    
More information about the cfe-commits
mailing list