[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Modules / submodule-visibility.cpp
blob6a1a816ed67e50eb0c091690a4de9509a3712550
1 // RUN: rm -rf %t
2 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%S/Inputs/submodule-visibility -verify %s -DALLOW_NAME_LEAKAGE
3 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-local-submodule-visibility -fmodules-cache-path=%t -I%S/Inputs/submodule-visibility -verify %s -DIMPORT
4 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-local-submodule-visibility -fmodules-cache-path=%t -fmodule-name=x -I%S/Inputs/submodule-visibility -verify %s
5 // RUN: %clang_cc1 -fimplicit-module-maps -fmodules-local-submodule-visibility -I%S/Inputs/submodule-visibility -verify %s
6 // RUN: %clang_cc1 -fmodule-map-file=%S/Inputs/submodule-visibility/module.modulemap -fmodules-local-submodule-visibility -I%S/Inputs/submodule-visibility -verify %s
7 //
8 // Ensure the driver forwards the relevant flags when -fmodules is disabled.
9 // FIXME: -fdelayed-template-parsing doesn't properly interact with module visibility yet.
10 // RUN: %clang -fimplicit-module-maps -Xclang -fmodules-local-submodule-visibility -I%S/Inputs/submodule-visibility -fsyntax-only -Xclang -verify %s -fno-delayed-template-parsing
11 // RUN: %clang -fmodule-map-file=%S/Inputs/submodule-visibility/module.modulemap -Xclang -fmodules-local-submodule-visibility -I%S/Inputs/submodule-visibility -fsyntax-only -Xclang -verify %s -fno-delayed-template-parsing
13 // Explicit module builds.
14 // RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -emit-module -x c++-module-map %S/Inputs/submodule-visibility/module.modulemap -fmodule-name=other -o %t/other.pcm
15 // RUN: %clang_cc1 -fmodules -fmodule-map-file=%S/Inputs/submodule-visibility/module.modulemap -fmodules-local-submodule-visibility -fmodule-file=%t/other.pcm -verify -fmodule-name=x -I%S/Inputs/submodule-visibility %s
16 // RUN: %clang_cc1 -fmodules -fmodule-map-file=%S/Inputs/submodule-visibility/module.modulemap -fmodule-file=%t/other.pcm -verify -fmodule-name=x -I%S/Inputs/submodule-visibility %s -DALLOW_TEXTUAL_NAME_LEAKAGE
18 #include "a.h"
19 #include "b.h"
21 #if ALLOW_NAME_LEAKAGE
22 // expected-no-diagnostics
23 #elif IMPORT
24 // expected-error@-6 {{could not build module 'x'}}
25 #elif ALLOW_TEXTUAL_NAME_LEAKAGE
26 // expected-warning@b.h:7 {{A is defined}}
27 #else
28 // The use of -fmodule-name=x causes us to textually include the above headers.
29 // The submodule visibility rules are still applied in this case.
31 // expected-error@b.h:1 {{missing '#include "a.h"'; 'n' must be declared}}
32 // expected-note@a.h:1 {{here}}
33 #endif
35 int k = n + m; // OK, a and b are visible here.
37 #ifndef A
38 #error A is not defined
39 #endif
41 #ifndef B
42 #error B is not defined
43 #endif
45 // Ensure we don't compute the linkage of this struct before we find it has a
46 // typedef name for linkage purposes.
47 typedef struct {
48 int p;
49 void (*f)(int p);
50 } name_for_linkage;
52 void g() { b_template<int>(); }