[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Modules / module-private.cpp
blob4036c345ef3c935af789c74fa756ecdc2439debf
1 // RUN: rm -rf %t
2 // RUN: %clang_cc1 -std=c++17 -fmodules -fimplicit-module-maps -x objective-c++ -fmodules-cache-path=%t -fmodule-name=module_private_left -emit-module %S/Inputs/module.modulemap
3 // RUN: %clang_cc1 -std=c++17 -fmodules -fimplicit-module-maps -x objective-c++ -fmodules-cache-path=%t -fmodule-name=module_private_right -emit-module %S/Inputs/module.modulemap
4 // RUN: %clang_cc1 -std=c++17 -fmodules -fimplicit-module-maps -x objective-c++ -fmodules-cache-path=%t -I %S/Inputs %s -verify
5 // FIXME: When we have a syntax for modules in C++, use that.
7 @import module_private_left;
8 @import module_private_right;
10 void test() {
11 int &ir = f0(1.0); // okay: f0() from 'right' is not visible
14 int test_broken() {
15 HiddenStruct hidden; // expected-error{{unknown type name 'HiddenStruct'}}
16 Integer i; // expected-error{{unknown type name 'Integer'}}
18 int *ip = 0;
19 f1(ip); // expected-error{{use of undeclared identifier 'f1'}}
21 vector<int> vec; // expected-error{{no template named 'vector'}}
23 VisibleStruct vs;
24 vs.field = 0;
25 vs.setField(1);
27 return hidden_var; // expected-error{{use of undeclared identifier 'hidden_var'}}
30 // Check for private redeclarations of public entities.
31 template<typename T>
32 class public_class_template;
34 template<typename T>
35 __module_private__ class public_class_template;
38 typedef int public_typedef;
39 typedef __module_private__ int public_typedef;
41 extern int public_var;
42 extern __module_private__ int public_var;
44 void public_func();
45 __module_private__ void public_func();
47 template<typename T>
48 void public_func_template();
49 template<typename T>
50 __module_private__ void public_func_template();
52 struct public_struct;
53 __module_private__ struct public_struct;
55 // Check for attempts to make specializations private
56 template<> __module_private__ void public_func_template<int>(); // expected-error{{template specialization cannot be declared __module_private__}}
58 template<typename T>
59 struct public_class {
60 struct inner_struct;
61 static int static_var;
63 friend __module_private__ void public_func_friend();
64 friend __module_private__ struct public_struct_friend;
67 template<> __module_private__ struct public_class<int>::inner_struct { }; // expected-error{{member specialization cannot be declared __module_private__}}
68 template<> __module_private__ int public_class<int>::static_var = 17; // expected-error{{member specialization cannot be declared __module_private__}}
70 template<>
71 __module_private__ struct public_class<float> { }; // expected-error{{template specialization cannot be declared __module_private__}}
73 template<typename T>
74 __module_private__ struct public_class<T *> { }; // expected-error{{partial specialization cannot be declared __module_private__}}
76 // Check for attempts to make parameters and variables with automatic
77 // storage module-private.
79 void local_var_private(__module_private__ int param) { // expected-error{{parameter 'param' cannot be declared __module_private__}}
80 __module_private__ struct Local { int x, y; } local; //expected-error{{local variable 'local' cannot be declared __module_private__}}
82 __module_private__ auto [x, y] = local; // expected-error {{local variable '[x, y]' cannot be declared __module_private__}}
84 __module_private__ struct OtherLocal { int x; }; // expected-error{{local struct cannot be declared __module_private__}}
86 typedef __module_private__ int local_typedef; // expected-error{{typedef 'local_typedef' cannot be declared __module_private__}}
89 void param_private(__module_private__ int) {} // expected-error {{parameter '' cannot be declared __module_private}}
91 // Check struct size
92 struct LikeVisibleStruct {
93 int field;
94 virtual void setField(int f);
97 int check_struct_size[sizeof(VisibleStruct) == sizeof(LikeVisibleStruct)? 1 : -1];