1 2 // RUN: rm -rf %t 3 // RUN: mkdir -p %t 4 // RUN: split-file %s %t 5 6 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex2-tu1.cpp \ 7 // RUN: -o %t/B_Y.pcm 8 9 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex2-tu2.cpp \ 10 // RUN: -fmodule-file=%t/B_Y.pcm -o %t/B.pcm 11 12 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex2-tu3.cpp \ 13 // RUN: -o %t/B_X1.pcm -verify 14 15 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex2-tu4.cpp \ 16 // RUN:-fmodule-file=%t/B.pcm -o %t/B_X2.pcm 17 18 // RUN: %clang_cc1 -std=c++20 -emit-obj %t/std10-1-ex2-tu5.cpp \ 19 // RUN: -fmodule-file=%t/B.pcm -o %t/b_tu5.o 20 21 // RUN: %clang_cc1 -std=c++20 -S %t/std10-1-ex2-tu6.cpp \ 22 // RUN: -fmodule-file=%t/B.pcm -o %t/b_tu6.s -verify 23 24 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex2-tu7.cpp \ 25 // RUN: -fmodule-file=%t/B_X2.pcm -o %t/B_X3.pcm -verify 26 27 //--- std10-1-ex2-tu1.cpp 28 module B:Y; 29 int y(); 30 // expected-no-diagnostics 31 32 //--- std10-1-ex2-tu2.cpp 33 export module B; 34 import :Y; 35 int n = y(); 36 // expected-no-diagnostics 37 38 //--- std10-1-ex2-tu3.cpp 39 module B:X1; // does not implicitly import B 40 int &a = n; // expected-error {{use of undeclared identifier }} 41 42 //--- std10-1-ex2-tu4.cpp 43 module B:X2; // does not implicitly import B 44 import B; 45 int &b = n; // OK 46 // expected-no-diagnostics 47 48 //--- std10-1-ex2-tu5.cpp 49 module B; // implicitly imports B 50 int &c = n; // OK 51 // expected-no-diagnostics 52 53 //--- std10-1-ex2-tu6.cpp 54 import B; 55 // error, n is module-local and this is not a module. 56 int &c = n; // expected-error {{declaration of 'n' must be imported}} 57 // expected-note@* {{declaration here is not visible}} 58 59 //--- std10-1-ex2-tu7.cpp 60 // expected-no-diagnostics 61 module B:X3; // does not implicitly import B 62 import :X2; // X2 is an implementation unit import B. 63 // According to [module.import]p7: 64 // Additionally, when a module-import-declaration in a module unit of some 65 // module M imports another module unit U of M, it also imports all 66 // translation units imported by non-exported module-import-declarations in 67 // the module unit purview of U. 68 // 69 // So B is imported in B:X3 due to B:X2 imported B. So n is visible here. 70 int &c = n; 71