[clang] [NFC][clang][Modules] Add regression test for implicit lambda capture from merged module copies (PR #222020)

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 27 20:23:17 PDT 2026


https://github.com/ChuanqiXu9 updated https://github.com/llvm/llvm-project/pull/222020

>From 0032d89e3c17b96bf386140d248f6685dbd9a135 Mon Sep 17 00:00:00 2001
From: Adarsh-Me <adarsh at example.com>
Date: Tue, 8 Sep 2026 20:24:17 +0530
Subject: [PATCH 1/2] [clang][Modules] Add regression test for implicit lambda
 capture from merged module copies

Adds a regression test for
https://github.com/llvm/llvm-project/issues/221548: when the same
header is textually included into the global module fragments of two
different module interface units, instantiating an out-of-line member
template whose body contains a lambda capturing a local variable must
keep the capture. The test fails on compilers affected by the issue
(static assertion error with the bogus 'captures not currently
allowed' note) and passes on current main.
---
 clang/test/Modules/GH221548.cpp | 59 +++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 clang/test/Modules/GH221548.cpp

diff --git a/clang/test/Modules/GH221548.cpp b/clang/test/Modules/GH221548.cpp
new file mode 100644
index 0000000000000..9f1e01f97aaae
--- /dev/null
+++ b/clang/test/Modules/GH221548.cpp
@@ -0,0 +1,59 @@
+// From https://github.com/llvm/llvm-project/issues/221548
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++23 -emit-module-interface %t/stdish.cppm -o %t/stdish.pcm
+// RUN: %clang_cc1 -std=c++23 -emit-module-interface %t/wrap.cppm -o %t/wrap.pcm
+// RUN: %clang_cc1 -std=c++23 -fmodule-file=stdish=%t/stdish.pcm -fmodule-file=wrap=%t/wrap.pcm -emit-module-interface %t/side.cppm -o %t/side.pcm
+// RUN: %clang_cc1 -std=c++23 -fmodule-file=stdish=%t/stdish.pcm -fmodule-file=wrap=%t/wrap.pcm -fmodule-file=side=%t/side.pcm %t/use.cc -fsyntax-only -verify
+
+//--- mine.h
+#pragma once
+namespace mine {
+
+template <class value_type>
+struct box {
+  value_type value{};
+  template <class other_kind>
+  constexpr value_type twice(other_kind extra) const;
+};
+
+template <class value_type>
+template <class other_kind>
+constexpr value_type box<value_type>::twice(other_kind extra) const {
+  value_type held = value + static_cast<value_type>(extra);
+  auto go = [&] { held = held + held; };
+  go();
+  return held;
+}
+
+}  // namespace mine
+
+//--- stdish.cppm
+module;
+#include "mine.h"
+export module stdish;
+export namespace mine { using mine::box; }
+
+//--- wrap.cppm
+module;
+#include "mine.h"
+export module wrap;
+export template <class value_type> using holder = mine::box<value_type>;
+
+//--- side.cppm
+export module side;
+import stdish;
+export constexpr int one() { return mine::box<long>{21}.twice(0) == 42 ? 42 : 0; }
+
+//--- use.cc
+// expected-no-diagnostics
+import wrap;
+import stdish;
+import side;
+
+int main() {
+  holder<int> spare{1};
+  static_assert(one() == 42);
+  static_assert(mine::box<int>{21}.twice(0) == 42);
+}

>From 609cb782bedd75f77133dfe8278058296ed36d04 Mon Sep 17 00:00:00 2001
From: Adarsh-Me <adarsh at example.com>
Date: Thu, 10 Sep 2026 03:30:53 +0530
Subject: [PATCH 2/2] Test again with reduced BMI

---
 clang/test/Modules/GH221548.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/clang/test/Modules/GH221548.cpp b/clang/test/Modules/GH221548.cpp
index 9f1e01f97aaae..d53efc3ad788d 100644
--- a/clang/test/Modules/GH221548.cpp
+++ b/clang/test/Modules/GH221548.cpp
@@ -6,6 +6,12 @@
 // RUN: %clang_cc1 -std=c++23 -emit-module-interface %t/wrap.cppm -o %t/wrap.pcm
 // RUN: %clang_cc1 -std=c++23 -fmodule-file=stdish=%t/stdish.pcm -fmodule-file=wrap=%t/wrap.pcm -emit-module-interface %t/side.cppm -o %t/side.pcm
 // RUN: %clang_cc1 -std=c++23 -fmodule-file=stdish=%t/stdish.pcm -fmodule-file=wrap=%t/wrap.pcm -fmodule-file=side=%t/side.pcm %t/use.cc -fsyntax-only -verify
+//
+// Test again with reduced BMI.
+// RUN: %clang_cc1 -std=c++23 -emit-reduced-module-interface %t/stdish.cppm -o %t/stdish.pcm
+// RUN: %clang_cc1 -std=c++23 -emit-reduced-module-interface %t/wrap.cppm -o %t/wrap.pcm
+// RUN: %clang_cc1 -std=c++23 -fmodule-file=stdish=%t/stdish.pcm -fmodule-file=wrap=%t/wrap.pcm -emit-reduced-module-interface %t/side.cppm -o %t/side.pcm
+// RUN: %clang_cc1 -std=c++23 -fmodule-file=stdish=%t/stdish.pcm -fmodule-file=wrap=%t/wrap.pcm -fmodule-file=side=%t/side.pcm %t/use.cc -fsyntax-only -verify
 
 //--- mine.h
 #pragma once



More information about the cfe-commits mailing list