| 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=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=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=M1.pcm -fmodule-file=M2=M2.pcm -fmodule-file=stuff=stuff.pcm \ |
| 22 |
// RUN: -fsyntax-only -verify |
| 23 |
|
| 24 |
//--- std-10-6-ex1-decl.h |
| 25 |
struct X; |
| 26 |
|
| 27 |
//--- std-10-6-ex1-defn.h |
| 28 |
struct X {}; |
| 29 |
|
| 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; } |
| 34 |
|
| 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; |
| 39 |
|
| 40 |
export template <typename T> void f(T t) { |
| 41 |
X x; |
| 42 |
foo(t, x); |
| 43 |
} |
| 44 |
|
| 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) |
| 48 |
|
| 49 |
import stuff; |
| 50 |
export template <typename T> void g(T t) { |
| 51 |
X *x; |
| 52 |
bar(t, x); |
| 53 |
} |
| 54 |
|
| 55 |
//--- std-10-6-ex1-use.cpp |
| 56 |
import M1; |
| 57 |
import M2; |
| 58 |
|
| 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}} |
| 67 |
} |