[PATCH] D116097: [NFC] [C++20] [Modules] Add tests for template instantiation in transitive imported module

Chuanqi Xu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 21 19:23:10 PST 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG759f3e297c07: [NFC] [C++20] [Modules] Add tests for template instantiation in transitively… (authored by ChuanqiXu).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116097/new/

https://reviews.llvm.org/D116097

Files:
  clang/test/Modules/Inputs/module-transtive-instantiation/Templ.cppm
  clang/test/Modules/Inputs/module-transtive-instantiation/bar.cppm
  clang/test/Modules/module-transtive-instantiation-2.cpp
  clang/test/Modules/module-transtive-instantiation.cpp


Index: clang/test/Modules/module-transtive-instantiation.cpp
===================================================================
--- /dev/null
+++ clang/test/Modules/module-transtive-instantiation.cpp
@@ -0,0 +1,13 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: %clang_cc1 -std=c++20 %S/Inputs/module-transtive-instantiation/Templ.cppm -emit-module-interface -o %t/Templ.pcm
+// RUN: %clang_cc1 -std=c++20 %S/Inputs/module-transtive-instantiation/bar.cppm  -emit-module-interface -fprebuilt-module-path=%t -o %t/bar.pcm
+// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %s -fsyntax-only -verify
+
+import bar;
+int foo() {
+    // FIXME: It shouldn't be an error. Since the `G` is already imported in bar.
+    return bar<int>(); // expected-error at Inputs/module-transtive-instantiation/bar.cppm:5 {{definition of 'G' must be imported from module 'Templ' before it is required}}
+                       // expected-note at -1 {{in instantiation of function template specialization 'bar<int>' requested here}}
+                       // expected-note at Inputs/module-transtive-instantiation/Templ.cppm:3 {{definition here is not reachable}}
+}
Index: clang/test/Modules/module-transtive-instantiation-2.cpp
===================================================================
--- /dev/null
+++ clang/test/Modules/module-transtive-instantiation-2.cpp
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: %clang_cc1 -std=c++20 %S/Inputs/module-transtive-instantiation/Templ.cppm -emit-module-interface -o %t/Templ.pcm
+// RUN: %clang_cc1 -std=c++20 %S/Inputs/module-transtive-instantiation/bar.cppm  -emit-module-interface -fprebuilt-module-path=%t -o %t/bar.pcm
+// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %s -fsyntax-only -verify
+
+import bar;
+int foo() {
+    G<int> g;    // expected-error {{declaration of 'G' must be imported from module 'Templ' before it is required}}
+    return g();  // expected-note at Inputs/module-transtive-instantiation/Templ.cppm:3 {{declaration here is not visible}}
+}
Index: clang/test/Modules/Inputs/module-transtive-instantiation/bar.cppm
===================================================================
--- /dev/null
+++ clang/test/Modules/Inputs/module-transtive-instantiation/bar.cppm
@@ -0,0 +1,6 @@
+export module bar;
+import Templ;
+export template<class T>
+int bar() {
+    return G<T>()();
+}
Index: clang/test/Modules/Inputs/module-transtive-instantiation/Templ.cppm
===================================================================
--- /dev/null
+++ clang/test/Modules/Inputs/module-transtive-instantiation/Templ.cppm
@@ -0,0 +1,8 @@
+export module Templ;
+export template <class T>
+class G {
+public:
+    T operator()() {
+        return T();
+    }
+};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116097.395787.patch
Type: text/x-patch
Size: 2739 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211222/ecddca6f/attachment-0001.bin>


More information about the cfe-commits mailing list