1 // RUN: rm -rf %t
2 // RUN: split-file %s %t
3 // RUN: cd %t
4 
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
7 
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
10 
11 // RUN: %clang_cc1 -std=c++20 -emit-module-interface std-10-6-ex1-stuff.cpp \
12 // RUN: -o stuff.pcm
13 
14 // RUN: %clang_cc1 -std=c++20 -emit-module-interface std-10-6-ex1-M1.cpp \
15 // RUN: -fmodule-file=stuff.pcm -o M1.pcm  -fmodule-file=defn.pcm
16 
17 // RUN: %clang_cc1 -std=c++20 -emit-module-interface std-10-6-ex1-M2.cpp \
18 // RUN: -fmodule-file=stuff.pcm -o M2.pcm  -fmodule-file=decl.pcm
19 
20 // RUN: %clang_cc1 -std=c++20 std-10-6-ex1-use.cpp \
21 // RUN: -fmodule-file=M1.pcm -fmodule-file=M2.pcm  -fsyntax-only -verify
22 
23 //--- std-10-6-ex1-decl.h
24 struct X;
25 
26 //--- std-10-6-ex1-defn.h
27 struct X {};
28 
29 //--- std-10-6-ex1-stuff.cpp
30 export module stuff;
foo(T,U u)31 export template <typename T, typename U> void foo(T, U u) { auto v = u; }
bar(T,U u)32 export template <typename T, typename U> void bar(T, U u) { auto v = *u; }
33 
34 //--- std-10-6-ex1-M1.cpp
35 export module M1;
36 import "std-10-6-ex1-defn.h"; // provides struct X {};
37 import stuff;
38 
f(T t)39 export template <typename T> void f(T t) {
40   X x;
41   foo(t, x);
42 }
43 
44 //--- std-10-6-ex1-M2.cpp
45 export module M2;
46 import "std-10-6-ex1-decl.h"; // provides struct X; (not a definition)
47 
48 import stuff;
g(T t)49 export template <typename T> void g(T t) {
50   X *x;
51   bar(t, x);
52 }
53 
54 //--- std-10-6-ex1-use.cpp
55 import M1;
56 import M2;
57 
test()58 void test() {
59   f(0);
60   // It is unspecified whether the instantiation of g(0) is valid here.
61   // We choose to make it invalid here.
62   g(0); // expected-error@* {{definition of 'X' must be imported from module}}
63         // expected-note@* {{in instantiation of function template specialization 'bar<int, X *>'}}
64         // expected-note@* {{in instantiation of function template specialization}}
65         // expected-note@* {{definition here is not reachable}}
66 }
67