[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.
This commit is contained in:
Chuanqi Xu 2021-12-21 17:36:50 +08:00
parent c2f2bb066b
commit 4f103e9561
4 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,8 @@
export module Templ;
export template <class T>
class G {
public:
T operator()() {
return T();
}
};

View File

@ -0,0 +1,6 @@
export module bar;
import Templ;
export template<class T>
int bar() {
return G<T>()();
}

View File

@ -0,0 +1,11 @@
// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: %clang -std=c++20 %S/Inputs/module-transtive-instantiation/Templ.cppm --precompile -o %t/Templ.pcm
// RUN: %clang -std=c++20 %S/Inputs/module-transtive-instantiation/bar.cppm --precompile -fprebuilt-module-path=%t -o %t/bar.pcm
// RUN: %clang -std=c++20 -fprebuilt-module-path=%t %s -c -Xclang -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}}
}

View File

@ -0,0 +1,13 @@
// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: %clang -std=c++20 %S/Inputs/module-transtive-instantiation/Templ.cppm --precompile -o %t/Templ.pcm
// RUN: %clang -std=c++20 %S/Inputs/module-transtive-instantiation/bar.cppm --precompile -fprebuilt-module-path=%t -o %t/bar.pcm
// RUN: %clang -std=c++20 -fprebuilt-module-path=%t %s -c -Xclang -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}}
}