Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / module / module.context / p7.cpp
blob9afde972e9225ac7e3e607676e882cc986fd097a
1 // RUN: rm -rf %t
2 // RUN: split-file %s %t
3 // RUN: cd %t
5 // RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-header-unit-header std-10-6-ex1-decl.h \
6 // RUN: -o decl.pcm
8 // RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-header-unit-header std-10-6-ex1-defn.h \
9 // RUN: -o defn.pcm
11 // RUN: %clang_cc1 -std=c++20 -emit-module-interface std-10-6-ex1-stuff.cpp \
12 // RUN: -o stuff.pcm
14 // RUN: %clang_cc1 -std=c++20 -emit-module-interface std-10-6-ex1-M1.cpp \
15 // RUN: -fmodule-file=stuff=stuff.pcm -o M1.pcm -fmodule-file=defn.pcm
17 // RUN: %clang_cc1 -std=c++20 -emit-module-interface std-10-6-ex1-M2.cpp \
18 // RUN: -fmodule-file=stuff=stuff.pcm -o M2.pcm -fmodule-file=decl.pcm
20 // RUN: %clang_cc1 -std=c++20 std-10-6-ex1-use.cpp \
21 // RUN: -fmodule-file=M1=M1.pcm -fmodule-file=M2=M2.pcm -fmodule-file=stuff=stuff.pcm \
22 // RUN: -fsyntax-only -verify
24 //--- std-10-6-ex1-decl.h
25 struct X;
27 //--- std-10-6-ex1-defn.h
28 struct X {};
30 //--- std-10-6-ex1-stuff.cpp
31 export module stuff;
32 export template <typename T, typename U> void foo(T, U u) { auto v = u; }
33 export template <typename T, typename U> void bar(T, U u) { auto v = *u; }
35 //--- std-10-6-ex1-M1.cpp
36 export module M1;
37 import "std-10-6-ex1-defn.h"; // provides struct X {};
38 import stuff;
40 export template <typename T> void f(T t) {
41 X x;
42 foo(t, x);
45 //--- std-10-6-ex1-M2.cpp
46 export module M2;
47 import "std-10-6-ex1-decl.h"; // provides struct X; (not a definition)
49 import stuff;
50 export template <typename T> void g(T t) {
51 X *x;
52 bar(t, x);
55 //--- std-10-6-ex1-use.cpp
56 import M1;
57 import M2;
59 void test() {
60 f(0);
61 // It is unspecified whether the instantiation of g(0) is valid here.
62 // We choose to make it invalid here.
63 g(0); // expected-error@* {{definition of 'X' must be imported from module}}
64 // expected-note@* {{in instantiation of function template specialization 'bar<int, X *>'}}
65 // expected-note@* {{in instantiation of function template specialization}}
66 // expected-note@* {{definition here is not reachable}}