blob: 81b2aca3fb66c0ce2c4efd059c0cc7660748a563 [file] [log] [blame]
Douglas Gregor8d267c52011-09-09 02:06:17 +00001// RUN: mkdir -p %t
2// RUN: %clang_cc1 -x c++ -emit-module -o %t/left.pcm %s -D MODULE_LEFT
3// RUN: %clang_cc1 -x c++ -emit-module -o %t/right.pcm %s -D MODULE_RIGHT
Douglas Gregor9a6da692011-09-12 20:41:59 +00004// RUN: %clang_cc1 -fmodule-cache-path %t %s -verify
Douglas Gregor8d267c52011-09-09 02:06:17 +00005
6#if defined(MODULE_LEFT)
7
Douglas Gregor6311d2b2011-09-09 18:32:39 +00008__module_private__ struct HiddenStruct;
9
10struct HiddenStruct {
Douglas Gregor8d267c52011-09-09 02:06:17 +000011};
12
13
14int &f0(int);
15
16template<typename T>
17__module_private__ void f1(T*);
18
19template<typename T>
Douglas Gregor6311d2b2011-09-09 18:32:39 +000020void f1(T*);
21
22template<typename T>
23__module_private__ class vector;
24
25template<typename T>
26class vector {
Douglas Gregor8d267c52011-09-09 02:06:17 +000027};
28
29vector<float> vec_float;
30
31typedef __module_private__ int Integer;
Douglas Gregor6311d2b2011-09-09 18:32:39 +000032typedef int Integer;
Douglas Gregor8d267c52011-09-09 02:06:17 +000033
34#elif defined(MODULE_RIGHT)
35__module_private__ double &f0(double);
Douglas Gregor6311d2b2011-09-09 18:32:39 +000036double &f0(double);
Douglas Gregor8d267c52011-09-09 02:06:17 +000037
38__module_private__ int hidden_var;
39
40inline void test_f0_in_right() {
41 double &dr = f0(hidden_var);
42}
Douglas Gregor591dc842011-09-12 16:11:24 +000043
44struct VisibleStruct {
45 __module_private__ int field;
Douglas Gregorfe522c22011-09-13 15:37:05 +000046 __module_private__ virtual void setField(int f);
Douglas Gregor591dc842011-09-12 16:11:24 +000047};
48
Douglas Gregor8d267c52011-09-09 02:06:17 +000049#else
50__import_module__ left;
51__import_module__ right;
52
53void test() {
54 int &ir = f0(1.0); // okay: f0() from 'right' is not visible
55}
56
57int test_broken() {
58 HiddenStruct hidden; // expected-error{{use of undeclared identifier 'HiddenStruct'}}
59
60 Integer i; // expected-error{{use of undeclared identifier 'Integer'}}
61
62 int *ip = 0;
63 f1(ip); // expected-error{{use of undeclared identifier 'f1'}}
64
65 vector<int> vec; // expected-error{{use of undeclared identifier 'vector'}} \
66 // expected-error{{expected '(' for function-style cast or type construction}} \
67 // expected-error{{use of undeclared identifier 'vec'}}
68
Douglas Gregor591dc842011-09-12 16:11:24 +000069 VisibleStruct vs;
70 vs.field = 0; // expected-error{{no member named 'field' in 'VisibleStruct'}}
71 vs.setField(1); // expected-error{{no member named 'setField' in 'VisibleStruct'}}
72
Douglas Gregor8d267c52011-09-09 02:06:17 +000073 return hidden_var; // expected-error{{use of undeclared identifier 'hidden_var'}}
74}
75
Douglas Gregore7612302011-09-09 19:05:14 +000076// Check for private redeclarations of public entities.
77template<typename T>
78class public_class_template; // expected-note{{previous declaration is here}}
79
80template<typename T>
81__module_private__ class public_class_template; // expected-error{{__module_private__ declaration of 'public_class_template' follows public declaration}}
82
83
84typedef int public_typedef; // expected-note{{previous declaration is here}}
85typedef __module_private__ int public_typedef; // expected-error{{__module_private__ declaration of 'public_typedef' follows public declaration}}
86
87extern int public_var; // expected-note{{previous declaration is here}}
88extern __module_private__ int public_var; // expected-error{{__module_private__ declaration of 'public_var' follows public declaration}}
89
90void public_func(); // expected-note{{previous declaration is here}}
91__module_private__ void public_func(); // expected-error{{__module_private__ declaration of 'public_func' follows public declaration}}
92
93template<typename T>
94void public_func_template(); // expected-note{{previous declaration is here}}
95template<typename T>
96__module_private__ void public_func_template(); // expected-error{{__module_private__ declaration of 'public_func_template' follows public declaration}}
97
98struct public_struct; // expected-note{{previous declaration is here}}
99__module_private__ struct public_struct; // expected-error{{__module_private__ declaration of 'public_struct' follows public declaration}}
100
Douglas Gregord023aec2011-09-09 20:53:38 +0000101// Check for attempts to make specializations private
102template<> __module_private__ void public_func_template<int>(); // expected-error{{template specialization cannot be declared __module_private__}}
103
104template<typename T>
105struct public_class {
106 struct inner_struct;
107 static int static_var;
Douglas Gregor6274d302011-09-09 21:14:29 +0000108
Douglas Gregorf3a762a2011-09-12 15:48:15 +0000109 friend __module_private__ void public_func_friend();
110 friend __module_private__ struct public_struct_friend;
Douglas Gregord023aec2011-09-09 20:53:38 +0000111};
112
113template<> __module_private__ struct public_class<int>::inner_struct { }; // expected-error{{member specialization cannot be declared __module_private__}}
114template<> __module_private__ int public_class<int>::static_var = 17; // expected-error{{member specialization cannot be declared __module_private__}}
115
116template<>
117__module_private__ struct public_class<float> { }; // expected-error{{template specialization cannot be declared __module_private__}}
118
119template<typename T>
120__module_private__ struct public_class<T *> { }; // expected-error{{partial specialization cannot be declared __module_private__}}
Douglas Gregore7612302011-09-09 19:05:14 +0000121
Douglas Gregore3895852011-09-12 18:37:38 +0000122// Check for attempts to make parameters and variables with automatic
123// storage module-private.
124
125void local_var_private(__module_private__ int param) { // expected-error{{parameter 'param' cannot be declared __module_private__}}
126 __module_private__ struct Local { int x, y; } local; //expected-error{{local variable 'local' cannot be declared __module_private__}}
127
128 __module_private__ struct OtherLocal { int x; }; // expected-error{{local struct cannot be declared __module_private__}}
129
130 typedef __module_private__ int local_typedef; // expected-error{{typedef 'local_typedef' cannot be declared __module_private__}}
131}
Douglas Gregorfe522c22011-09-13 15:37:05 +0000132
133// Check struct size
134struct LikeVisibleStruct {
135 int field;
136 virtual void setField(int f);
137};
138
139int check_struct_size[sizeof(VisibleStruct) == sizeof(LikeVisibleStruct)? 1 : -1];
Douglas Gregor8d267c52011-09-09 02:06:17 +0000140#endif