https://github.com/ChuanqiXu9 created 
https://github.com/llvm/llvm-project/pull/222246

Close https://github.com/llvm/llvm-project/issues/222002

The root cause of the problem is, the deduction guide was removed in Reduced 
BMI. The fix is to preserve it if its referencing template will be remained.

>From 06d3a9104522079b5e6b3e1d1238cf11cfaff7e5 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu <[email protected]>
Date: Wed, 9 Sep 2026 14:04:16 +0800
Subject: [PATCH] [C++20] [Modules] Preserve DeductionGuideDecl if their parent
 are preserved

Close https://github.com/llvm/llvm-project/issues/222002

The root cause of the problem is, the deduction guide was removed in
Reduced BMI. The fix is to preserve it if its referencing template
will be remained.
---
 clang/lib/Serialization/ASTWriter.cpp |  3 ++
 clang/test/Modules/pr222002.cppm      | 44 +++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)
 create mode 100644 clang/test/Modules/pr222002.cppm

diff --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index de985b770cb01..286ec2a8a833e 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -4319,6 +4319,9 @@ static bool isModuleLocalDecl(NamedDecl *D) {
 
   // Deduction Guide are special here. Since their logical parent context are
   // not their actual parent.
+  if (auto *CDGD = dyn_cast<CXXDeductionGuideDecl>(D))
+    return isModuleLocalDecl(CDGD->getDeducedTemplate());
+
   if (auto *FTD = dyn_cast<FunctionTemplateDecl>(D))
     if (auto *CDGD = dyn_cast<CXXDeductionGuideDecl>(FTD->getTemplatedDecl()))
       return isModuleLocalDecl(CDGD->getDeducedTemplate());
diff --git a/clang/test/Modules/pr222002.cppm b/clang/test/Modules/pr222002.cppm
new file mode 100644
index 0000000000000..9d2ba7995a99a
--- /dev/null
+++ b/clang/test/Modules/pr222002.cppm
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/mod.cppm -emit-module-interface -o %t/mod.pcm
+// RUN: %clang_cc1 -std=c++20 %t/use.cpp -fmodule-file=mod=%t/mod.pcm \
+// RUN:   -fsyntax-only -verify
+//
+// Test  again with reduced BMI
+// RUN: %clang_cc1 -std=c++20 %t/mod.cppm -emit-reduced-module-interface \
+// RUN:   -o %t/mod.pcm
+// RUN: %clang_cc1 -std=c++20 %t/use.cpp -fmodule-file=mod=%t/mod.pcm \
+// RUN:   -fsyntax-only -verify
+
+//--- mod.cppm
+export module mod;
+
+export template <typename T> struct dependent {
+  dependent(int) {}
+};
+
+template <typename U> dependent(U) -> dependent<U>;
+
+export template <typename T> struct independent {
+  independent(int) {}
+};
+
+independent(int) -> independent<int>;
+
+export template <int N> struct nontype {
+  nontype(int) {}
+};
+
+nontype(int) -> nontype<1>;
+
+//--- use.cpp
+// expected-no-diagnostics
+import mod;
+
+void use() {
+  dependent d(1);
+  independent i(1);
+  nontype n(1);
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to