1 // RUN: rm -rf %t 2 // RUN: mkdir -p %t 3 // RUN: split-file %s %t 4 5 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu1.cpp \ 6 // RUN: -o %t/B.pcm 7 8 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu2.cpp \ 9 // RUN: -o %t/C.pcm 10 11 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu3.cpp \ 12 // RUN: -fmodule-file=%t/B.pcm -fmodule-file=%t/C.pcm -o %t/AOK1.pcm 13 14 // RUN: %clang_cc1 -std=c++20 -S %t/import-diags-tu4.cpp \ 15 // RUN: -fmodule-file=%t/AOK1.pcm -o %t/tu_3.s -verify 16 17 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu5.cpp \ 18 // RUN: -fmodule-file=%t/B.pcm -fmodule-file=%t/C.pcm -o %t/BC.pcm -verify 19 20 // RUN: %clang_cc1 -std=c++20 -S %t/import-diags-tu6.cpp \ 21 // RUN: -fmodule-file=%t/B.pcm -fmodule-file=%t/C.pcm -o %t/tu_5.s -verify 22 23 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu7.cpp \ 24 // RUN: -fmodule-file=%t/B.pcm -o %t/D.pcm -verify 25 26 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu8.cpp \ 27 // RUN: -fmodule-file=%t/B.pcm -o %t/D.pcm -verify 28 29 // RUN: %clang_cc1 -std=c++20 -S %t/import-diags-tu9.cpp \ 30 // RUN: -fmodule-file=%t/B.pcm -o %t/tu_8.s -verify 31 32 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu10.cpp \ 33 // RUN: -o %t/B.pcm -verify 34 35 // RUN: %clang_cc1 -std=c++20 -emit-obj %t/import-diags-tu11.cpp \ 36 // RUN: -fmodule-file=%t/C.pcm -o %t/impl.o 37 38 // Test diagnostics for incorrect module import sequences. 39 40 //--- import-diags-tu1.cpp 41 42 export module B; 43 44 int foo (); 45 46 // expected-no-diagnostics 47 48 //--- import-diags-tu2.cpp 49 50 export module C; 51 52 int bar (); 53 54 // expected-no-diagnostics 55 56 //--- import-diags-tu3.cpp 57 58 export module AOK1; 59 60 import B; 61 export import C; 62 63 export int theAnswer (); 64 65 // expected-no-diagnostics 66 67 //--- import-diags-tu4.cpp 68 69 module; 70 71 module AOK1; 72 73 export import C; // expected-error {{export declaration can only be used within a module interface unit}} 74 75 int theAnswer () { return 42; } 76 77 //--- import-diags-tu5.cpp 78 79 export module BC; 80 81 export import B; 82 83 int foo () { return 10; } 84 85 import C; // expected-error {{imports must immediately follow the module declaration}} 86 87 //--- import-diags-tu6.cpp 88 89 module B; // implicitly imports B. 90 91 int foo () { return 10; } 92 93 import C; // expected-error {{imports must immediately follow the module declaration}} 94 95 //--- import-diags-tu7.cpp 96 97 module; 98 // We can only have preprocessor directives here, which permits an include- 99 // translated header unit. However those are identified specifically by the 100 // preprocessor; non-preprocessed user code should not contain an 'import' here. 101 import B; // expected-error {{module imports cannot be in the global module fragment}} 102 103 export module D; 104 105 int delta (); 106 107 //--- import-diags-tu8.cpp 108 109 export module D; 110 111 int delta (); 112 113 module :private; 114 115 import B; // expected-error {{module imports cannot be in the private module fragment}} 116 117 //--- import-diags-tu9.cpp 118 119 module B; 120 121 import B; // expected-error {{import of module 'B' appears within its own implementation}} 122 123 //--- import-diags-tu10.cpp 124 125 export module B; 126 127 import B; // expected-error {{import of module 'B' appears within its own interface}} 128 129 //--- import-diags-tu11.cpp 130 131 int x; 132 133 import C; 134 135 int baz() { return 6174; } 136 137 // expected-no-diagnostics 138