Author: Chuanqi Xu Date: 2021-12-22T11:09:41+08:00 New Revision: 759f3e297c072165d044a3ac6fa3fc2f30df86ab
URL: https://github.com/llvm/llvm-project/commit/759f3e297c072165d044a3ac6fa3fc2f30df86ab DIFF: https://github.com/llvm/llvm-project/commit/759f3e297c072165d044a3ac6fa3fc2f30df86ab.diff LOG: [NFC] [C++20] [Modules] Add tests for template instantiation in transitively imported module This commit adds two test about template class instantiation in transitively imported module. They are used as pre-commit tests for successive patches. Differential Revision: https://reviews.llvm.org/D116097 Added: 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 Modified: Removed: ################################################################################ diff --git a/clang/test/Modules/Inputs/module-transtive-instantiation/Templ.cppm b/clang/test/Modules/Inputs/module-transtive-instantiation/Templ.cppm new file mode 100644 index 0000000000000..ee41b5374613f --- /dev/null +++ b/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(); + } +}; diff --git a/clang/test/Modules/Inputs/module-transtive-instantiation/bar.cppm b/clang/test/Modules/Inputs/module-transtive-instantiation/bar.cppm new file mode 100644 index 0000000000000..63cd595a642dc --- /dev/null +++ b/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>()(); +} diff --git a/clang/test/Modules/module-transtive-instantiation-2.cpp b/clang/test/Modules/module-transtive-instantiation-2.cpp new file mode 100644 index 0000000000000..b058cd77f4361 --- /dev/null +++ b/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@Inputs/module-transtive-instantiation/Templ.cppm:3 {{declaration here is not visible}} +} diff --git a/clang/test/Modules/module-transtive-instantiation.cpp b/clang/test/Modules/module-transtive-instantiation.cpp new file mode 100644 index 0000000000000..2c5c7ead8ad53 --- /dev/null +++ b/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@Inputs/module-transtive-instantiation/bar.cppm:5 {{definition of 'G' must be imported from module 'Templ' before it is required}} + // expected-note@-1 {{in instantiation of function template specialization 'bar<int>' requested here}} + // expected-note@Inputs/module-transtive-instantiation/Templ.cppm:3 {{definition here is not reachable}} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits