blob: eb932a8eb850fd1a8158d67c6292715b26e1023e [file] [log] [blame]
Douglas Gregor42583322011-11-16 05:16:30 +00001// RUN: rm -rf %t
Douglas Gregor66490142011-11-29 22:42:06 +00002// RUN: %clang_cc1 -fmodule-cache-path %t -fmodule-name=module_private_left -x c++ -emit-module %S/Inputs/module.map
3// RUN: %clang_cc1 -fmodule-cache-path %t -fmodule-name=module_private_right -x c++ -emit-module %S/Inputs/module.map
Douglas Gregor42583322011-11-16 05:16:30 +00004// RUN: %clang_cc1 -fmodule-cache-path %t %s -verify
Douglas Gregor8d267c52011-09-09 02:06:17 +00005
Douglas Gregor42583322011-11-16 05:16:30 +00006__import_module__ module_private_left;
7__import_module__ module_private_right;
Douglas Gregor8d267c52011-09-09 02:06:17 +00008
9void test() {
10 int &ir = f0(1.0); // okay: f0() from 'right' is not visible
11}
12
13int test_broken() {
14 HiddenStruct hidden; // expected-error{{use of undeclared identifier 'HiddenStruct'}}
15
16 Integer i; // expected-error{{use of undeclared identifier 'Integer'}}
17
18 int *ip = 0;
19 f1(ip); // expected-error{{use of undeclared identifier 'f1'}}
20
21 vector<int> vec; // expected-error{{use of undeclared identifier 'vector'}} \
22 // expected-error{{expected '(' for function-style cast or type construction}} \
23 // expected-error{{use of undeclared identifier 'vec'}}
24
Douglas Gregor591dc842011-09-12 16:11:24 +000025 VisibleStruct vs;
26 vs.field = 0; // expected-error{{no member named 'field' in 'VisibleStruct'}}
27 vs.setField(1); // expected-error{{no member named 'setField' in 'VisibleStruct'}}
28
Douglas Gregor8d267c52011-09-09 02:06:17 +000029 return hidden_var; // expected-error{{use of undeclared identifier 'hidden_var'}}
30}
31
Douglas Gregore7612302011-09-09 19:05:14 +000032// Check for private redeclarations of public entities.
33template<typename T>
34class public_class_template; // expected-note{{previous declaration is here}}
35
36template<typename T>
37__module_private__ class public_class_template; // expected-error{{__module_private__ declaration of 'public_class_template' follows public declaration}}
38
39
40typedef int public_typedef; // expected-note{{previous declaration is here}}
41typedef __module_private__ int public_typedef; // expected-error{{__module_private__ declaration of 'public_typedef' follows public declaration}}
42
43extern int public_var; // expected-note{{previous declaration is here}}
44extern __module_private__ int public_var; // expected-error{{__module_private__ declaration of 'public_var' follows public declaration}}
45
46void public_func(); // expected-note{{previous declaration is here}}
47__module_private__ void public_func(); // expected-error{{__module_private__ declaration of 'public_func' follows public declaration}}
48
49template<typename T>
50void public_func_template(); // expected-note{{previous declaration is here}}
51template<typename T>
52__module_private__ void public_func_template(); // expected-error{{__module_private__ declaration of 'public_func_template' follows public declaration}}
53
54struct public_struct; // expected-note{{previous declaration is here}}
55__module_private__ struct public_struct; // expected-error{{__module_private__ declaration of 'public_struct' follows public declaration}}
56
Douglas Gregord023aec2011-09-09 20:53:38 +000057// Check for attempts to make specializations private
58template<> __module_private__ void public_func_template<int>(); // expected-error{{template specialization cannot be declared __module_private__}}
59
60template<typename T>
61struct public_class {
62 struct inner_struct;
63 static int static_var;
Douglas Gregor6274d302011-09-09 21:14:29 +000064
Douglas Gregorf3a762a2011-09-12 15:48:15 +000065 friend __module_private__ void public_func_friend();
66 friend __module_private__ struct public_struct_friend;
Douglas Gregord023aec2011-09-09 20:53:38 +000067};
68
69template<> __module_private__ struct public_class<int>::inner_struct { }; // expected-error{{member specialization cannot be declared __module_private__}}
70template<> __module_private__ int public_class<int>::static_var = 17; // expected-error{{member specialization cannot be declared __module_private__}}
71
72template<>
73__module_private__ struct public_class<float> { }; // expected-error{{template specialization cannot be declared __module_private__}}
74
75template<typename T>
76__module_private__ struct public_class<T *> { }; // expected-error{{partial specialization cannot be declared __module_private__}}
Douglas Gregore7612302011-09-09 19:05:14 +000077
Douglas Gregore3895852011-09-12 18:37:38 +000078// Check for attempts to make parameters and variables with automatic
79// storage module-private.
80
81void local_var_private(__module_private__ int param) { // expected-error{{parameter 'param' cannot be declared __module_private__}}
82 __module_private__ struct Local { int x, y; } local; //expected-error{{local variable 'local' cannot be declared __module_private__}}
83
84 __module_private__ struct OtherLocal { int x; }; // expected-error{{local struct cannot be declared __module_private__}}
85
86 typedef __module_private__ int local_typedef; // expected-error{{typedef 'local_typedef' cannot be declared __module_private__}}
87}
Douglas Gregorfe522c22011-09-13 15:37:05 +000088
89// Check struct size
90struct LikeVisibleStruct {
91 int field;
92 virtual void setField(int f);
93};
94
95int check_struct_size[sizeof(VisibleStruct) == sizeof(LikeVisibleStruct)? 1 : -1];