blob: 246dcaf80e2497e4783a2dba93af07c5cb1e78f1 [file] [log] [blame]
Douglas Gregor42583322011-11-16 05:16:30 +00001// RUN: rm -rf %t
Douglas Gregorc13a34b2012-01-03 19:32:59 +00002// RUN: %clang_cc1 -fmodules -x objective-c++ -fmodule-cache-path %t -fmodule-name=module_private_left -emit-module %S/Inputs/module.map
3// RUN: %clang_cc1 -fmodules -x objective-c++ -fmodule-cache-path %t -fmodule-name=module_private_right -emit-module %S/Inputs/module.map
4// RUN: %clang_cc1 -fmodules -x objective-c++ -fmodule-cache-path %t %s -verify
5// FIXME: When we have a syntax for modules in C++, use that.
Douglas Gregor8d267c52011-09-09 02:06:17 +00006
Ted Kremenek32ad2ee2012-03-01 22:07:04 +00007@__experimental_modules_import module_private_left;
8@__experimental_modules_import module_private_right;
Douglas Gregor8d267c52011-09-09 02:06:17 +00009
10void test() {
11 int &ir = f0(1.0); // okay: f0() from 'right' is not visible
12}
13
14int test_broken() {
15 HiddenStruct hidden; // expected-error{{use of undeclared identifier 'HiddenStruct'}}
16
17 Integer i; // expected-error{{use of undeclared identifier 'Integer'}}
18
19 int *ip = 0;
20 f1(ip); // expected-error{{use of undeclared identifier 'f1'}}
21
22 vector<int> vec; // expected-error{{use of undeclared identifier 'vector'}} \
23 // expected-error{{expected '(' for function-style cast or type construction}} \
24 // expected-error{{use of undeclared identifier 'vec'}}
25
Douglas Gregor591dc842011-09-12 16:11:24 +000026 VisibleStruct vs;
27 vs.field = 0; // expected-error{{no member named 'field' in 'VisibleStruct'}}
28 vs.setField(1); // expected-error{{no member named 'setField' in 'VisibleStruct'}}
29
Douglas Gregor8d267c52011-09-09 02:06:17 +000030 return hidden_var; // expected-error{{use of undeclared identifier 'hidden_var'}}
31}
32
Douglas Gregore7612302011-09-09 19:05:14 +000033// Check for private redeclarations of public entities.
34template<typename T>
Douglas Gregor2ccd89c2011-12-20 18:11:52 +000035class public_class_template;
Douglas Gregore7612302011-09-09 19:05:14 +000036
37template<typename T>
Douglas Gregor2ccd89c2011-12-20 18:11:52 +000038__module_private__ class public_class_template;
Douglas Gregore7612302011-09-09 19:05:14 +000039
40
Douglas Gregor2ccd89c2011-12-20 18:11:52 +000041typedef int public_typedef;
42typedef __module_private__ int public_typedef;
Douglas Gregore7612302011-09-09 19:05:14 +000043
Douglas Gregor2ccd89c2011-12-20 18:11:52 +000044extern int public_var;
45extern __module_private__ int public_var;
Douglas Gregore7612302011-09-09 19:05:14 +000046
Douglas Gregor2ccd89c2011-12-20 18:11:52 +000047void public_func();
48__module_private__ void public_func();
Douglas Gregore7612302011-09-09 19:05:14 +000049
50template<typename T>
Douglas Gregor2ccd89c2011-12-20 18:11:52 +000051void public_func_template();
Douglas Gregore7612302011-09-09 19:05:14 +000052template<typename T>
Douglas Gregor2ccd89c2011-12-20 18:11:52 +000053__module_private__ void public_func_template();
Douglas Gregore7612302011-09-09 19:05:14 +000054
Douglas Gregor2ccd89c2011-12-20 18:11:52 +000055struct public_struct;
56__module_private__ struct public_struct;
Douglas Gregore7612302011-09-09 19:05:14 +000057
Douglas Gregord023aec2011-09-09 20:53:38 +000058// Check for attempts to make specializations private
59template<> __module_private__ void public_func_template<int>(); // expected-error{{template specialization cannot be declared __module_private__}}
60
61template<typename T>
62struct public_class {
63 struct inner_struct;
64 static int static_var;
Douglas Gregor6274d302011-09-09 21:14:29 +000065
Douglas Gregorf3a762a2011-09-12 15:48:15 +000066 friend __module_private__ void public_func_friend();
67 friend __module_private__ struct public_struct_friend;
Douglas Gregord023aec2011-09-09 20:53:38 +000068};
69
70template<> __module_private__ struct public_class<int>::inner_struct { }; // expected-error{{member specialization cannot be declared __module_private__}}
71template<> __module_private__ int public_class<int>::static_var = 17; // expected-error{{member specialization cannot be declared __module_private__}}
72
73template<>
74__module_private__ struct public_class<float> { }; // expected-error{{template specialization cannot be declared __module_private__}}
75
76template<typename T>
77__module_private__ struct public_class<T *> { }; // expected-error{{partial specialization cannot be declared __module_private__}}
Douglas Gregore7612302011-09-09 19:05:14 +000078
Douglas Gregore3895852011-09-12 18:37:38 +000079// Check for attempts to make parameters and variables with automatic
80// storage module-private.
81
82void local_var_private(__module_private__ int param) { // expected-error{{parameter 'param' cannot be declared __module_private__}}
83 __module_private__ struct Local { int x, y; } local; //expected-error{{local variable 'local' cannot be declared __module_private__}}
84
85 __module_private__ struct OtherLocal { int x; }; // expected-error{{local struct cannot be declared __module_private__}}
86
87 typedef __module_private__ int local_typedef; // expected-error{{typedef 'local_typedef' cannot be declared __module_private__}}
88}
Douglas Gregorfe522c22011-09-13 15:37:05 +000089
90// Check struct size
91struct LikeVisibleStruct {
92 int field;
93 virtual void setField(int f);
94};
95
96int check_struct_size[sizeof(VisibleStruct) == sizeof(LikeVisibleStruct)? 1 : -1];