Author: Chuanqi Xu
Date: 2025-12-16T17:37:53+08:00
New Revision: e60471d9fd7cd705eebd4c73ce63ec2c74fbd3a8

URL: 
https://github.com/llvm/llvm-project/commit/e60471d9fd7cd705eebd4c73ce63ec2c74fbd3a8
DIFF: 
https://github.com/llvm/llvm-project/commit/e60471d9fd7cd705eebd4c73ce63ec2c74fbd3a8.diff

LOG: [NFC] [C++20] [Modules] Add a test for module local template instantiation 
in namespace

This was found when debugging
https://github.com/llvm/llvm-project/issues/164466

I think more tests are always good. So I want to land this as a
regression check.

Added: 
    clang/test/Modules/module-local-template-instantiation-in-namespace.cppm

Modified: 
    

Removed: 
    


################################################################################
diff  --git 
a/clang/test/Modules/module-local-template-instantiation-in-namespace.cppm 
b/clang/test/Modules/module-local-template-instantiation-in-namespace.cppm
new file mode 100644
index 0000000000000..ec8ea338c1e34
--- /dev/null
+++ b/clang/test/Modules/module-local-template-instantiation-in-namespace.cppm
@@ -0,0 +1,59 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/p1.cppm -emit-module-interface -o %t/p1.pcm
+// RUN: %clang_cc1 -std=c++20 %t/p2.cppm -emit-module-interface 
-fmodule-file=m:p1=%t/p1.pcm -o %t/p2.pcm
+// RUN: %clang_cc1 -std=c++20 %t/m.cppm -emit-module-interface 
-fmodule-file=m:p1=%t/p1.pcm -fmodule-file=m:p2=%t/p2.pcm -o %t/m.pcm
+// RUN: %clang_cc1 -std=c++20 %t/use.cpp -fmodule-file=m=%t/m.pcm 
-fmodule-file=m:p1=%t/p1.pcm -fmodule-file=m:p2=%t/p2.pcm -fsyntax-only -verify
+
+// RUN: %clang_cc1 -std=c++20 %t/p1.cppm -emit-reduced-module-interface -o 
%t/p1.pcm
+// RUN: %clang_cc1 -std=c++20 %t/p2.cppm -emit-reduced-module-interface 
-fmodule-file=m:p1=%t/p1.pcm -o %t/p2.pcm
+// RUN: %clang_cc1 -std=c++20 %t/m.cppm -emit-reduced-module-interface 
-fmodule-file=m:p1=%t/p1.pcm -fmodule-file=m:p2=%t/p2.pcm -o %t/m.pcm
+// RUN: %clang_cc1 -std=c++20 %t/use.cpp -fmodule-file=m=%t/m.pcm 
-fmodule-file=m:p1=%t/p1.pcm -fmodule-file=m:p2=%t/p2.pcm -fsyntax-only -verify
+
+//--- p1.cppm
+export module m:p1;
+
+namespace nn {
+template<typename>
+class Incognita;
+
+export template<typename T>
+class Variable
+{
+public:
+  Incognita<T> foo() const { return {*this}; }
+};
+}
+
+//--- p2.cppm
+export module m:p2;
+
+import :p1;
+
+namespace nn {
+template<typename T>
+class Incognita
+{
+public:
+  Incognita(const Variable<T> &) {}
+};
+}
+
+//--- m.cppm
+export module m;
+
+export import :p1;
+export import :p2;
+
+//--- use.cpp
+// expected-no-diagnostics
+import m;
+
+auto foo()
+{
+    nn::Variable<double> x;
+
+    return x.foo();
+}


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

Reply via email to