xref: /llvm-project/clang/test/Modules/auto-import-unavailable.cpp (revision 8b7c0398b6a30d40de29e6f982a766c5016fc544)
1*8b7c0398SSean Silva // RUN: rm -rf %t
2*8b7c0398SSean Silva // RUN: not %clang_cc1 -x c++ -Rmodule-build -DMISSING_HEADER -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/auto-import-unavailable %s 2>&1 | FileCheck %s --check-prefix=MISSING-HEADER
3*8b7c0398SSean Silva // RUN: %clang_cc1 -x c++ -Rmodule-build -DNONREQUIRED_MISSING_HEADER -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/auto-import-unavailable %s 2>&1 | FileCheck %s --check-prefix=NONREQUIRED-MISSING-HEADER
4*8b7c0398SSean Silva // RUN: not %clang_cc1 -x c++ -Rmodule-build -DMISSING_REQUIREMENT -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/auto-import-unavailable %s 2>&1 | FileCheck %s --check-prefix=MISSING-REQUIREMENT
5*8b7c0398SSean Silva 
6*8b7c0398SSean Silva #ifdef MISSING_HEADER
7*8b7c0398SSean Silva 
8*8b7c0398SSean Silva // Even if the header we ask for is not missing, if the top-level module
9*8b7c0398SSean Silva // containing it has a missing header, then the whole top-level is
10*8b7c0398SSean Silva // unavailable and we issue an error.
11*8b7c0398SSean Silva 
12*8b7c0398SSean Silva // MISSING-HEADER: module.modulemap:2:27: error: header 'missing_header/missing.h' not found
13*8b7c0398SSean Silva // MISSING-HEADER-DAG: auto-import-unavailable.cpp:[[@LINE+1]]:10: note: submodule of top-level module 'missing_header' implicitly imported here
14*8b7c0398SSean Silva #include "missing_header/not_missing.h"
15*8b7c0398SSean Silva 
16*8b7c0398SSean Silva // We should not attempt to build the module.
17*8b7c0398SSean Silva // MISSING-HEADER-NOT: remark: building module
18*8b7c0398SSean Silva 
19*8b7c0398SSean Silva #endif // #ifdef MISSING_HEADER
20*8b7c0398SSean Silva 
21*8b7c0398SSean Silva 
22*8b7c0398SSean Silva #ifdef NONREQUIRED_MISSING_HEADER
23*8b7c0398SSean Silva 
24*8b7c0398SSean Silva // However, if the missing header is dominated by an unsatisfied
25*8b7c0398SSean Silva // `requires`, then that is acceptable.
26*8b7c0398SSean Silva // This also tests that an unsatisfied `requires` elsewhere in the
27*8b7c0398SSean Silva // top-level module doesn't affect an available module.
28*8b7c0398SSean Silva 
29*8b7c0398SSean Silva // NONREQUIRED-MISSING-HEADER: auto-import-unavailable.cpp:[[@LINE+2]]:10: remark: building module 'nonrequired_missing_header'
30*8b7c0398SSean Silva // NONREQUIRED-MISSING-HEADER: auto-import-unavailable.cpp:[[@LINE+1]]:10: remark: finished building module 'nonrequired_missing_header'
31*8b7c0398SSean Silva #include "nonrequired_missing_header/not_missing.h"
32*8b7c0398SSean Silva 
33*8b7c0398SSean Silva #endif // #ifdef NONREQUIRED_MISSING_HEADER
34*8b7c0398SSean Silva 
35*8b7c0398SSean Silva 
36*8b7c0398SSean Silva #ifdef MISSING_REQUIREMENT
37*8b7c0398SSean Silva 
38*8b7c0398SSean Silva // If the header is unavailable due to a missing requirement, an error
39*8b7c0398SSean Silva // should be emitted if a user tries to include it.
40*8b7c0398SSean Silva 
41*8b7c0398SSean Silva // MISSING-REQUIREMENT:module.modulemap:16:8: error: module 'missing_requirement' requires feature 'nonexistent_feature'
42*8b7c0398SSean Silva // MISSING-REQUIREMENT: auto-import-unavailable.cpp:[[@LINE+1]]:10: note: submodule of top-level module 'missing_requirement' implicitly imported here
43*8b7c0398SSean Silva #include "missing_requirement.h"
44*8b7c0398SSean Silva 
45*8b7c0398SSean Silva // MISSING-REQUIREMENT-NOT: remark: building module
46*8b7c0398SSean Silva 
47*8b7c0398SSean Silva #endif // #ifdef MISSING_REQUIREMENT
48