Douglas Gregor | 4258332 | 2011-11-16 05:16:30 +0000 | [diff] [blame] | 1 | // RUN: rm -rf %t |
Douglas Gregor | 953a61f | 2013-02-07 19:01:24 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -fmodules -x objective-c++ -fmodules-cache-path=%t -fmodule-name=module_private_left -emit-module %S/Inputs/module.map |
| 3 | // RUN: %clang_cc1 -fmodules -x objective-c++ -fmodules-cache-path=%t -fmodule-name=module_private_right -emit-module %S/Inputs/module.map |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 4 | // RUN: %clang_cc1 -fmodules -x objective-c++ -fmodules-cache-path=%t -I %S/Inputs %s -verify |
Douglas Gregor | c13a34b | 2012-01-03 19:32:59 +0000 | [diff] [blame] | 5 | // FIXME: When we have a syntax for modules in C++, use that. |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 6 | |
Douglas Gregor | 1b257af | 2012-12-11 22:11:52 +0000 | [diff] [blame] | 7 | @import module_private_left; |
| 8 | @import module_private_right; |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 9 | |
| 10 | void test() { |
| 11 | int &ir = f0(1.0); // okay: f0() from 'right' is not visible |
| 12 | } |
| 13 | |
| 14 | int test_broken() { |
Richard Smith | 40b2e19 | 2012-08-23 20:19:14 +0000 | [diff] [blame] | 15 | HiddenStruct hidden; // \ |
| 16 | // expected-error{{must use 'struct' tag to refer to type 'HiddenStruct' in this scope}} \ |
| 17 | // expected-error{{definition of 'struct HiddenStruct' must be imported}} |
Andy Gibbs | b42f200 | 2013-04-17 08:06:46 +0000 | [diff] [blame] | 18 | // expected-note@Inputs/module_private_left.h:3 {{previous definition is here}} |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 19 | |
Richard Smith | 40b2e19 | 2012-08-23 20:19:14 +0000 | [diff] [blame] | 20 | Integer i; // expected-error{{unknown type name 'Integer'}} |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 21 | |
| 22 | int *ip = 0; |
| 23 | f1(ip); // expected-error{{use of undeclared identifier 'f1'}} |
| 24 | |
| 25 | vector<int> vec; // expected-error{{use of undeclared identifier 'vector'}} \ |
| 26 | // expected-error{{expected '(' for function-style cast or type construction}} \ |
| 27 | // expected-error{{use of undeclared identifier 'vec'}} |
| 28 | |
Douglas Gregor | 591dc84 | 2011-09-12 16:11:24 +0000 | [diff] [blame] | 29 | VisibleStruct vs; |
| 30 | vs.field = 0; // expected-error{{no member named 'field' in 'VisibleStruct'}} |
| 31 | vs.setField(1); // expected-error{{no member named 'setField' in 'VisibleStruct'}} |
| 32 | |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 33 | return hidden_var; // expected-error{{use of undeclared identifier 'hidden_var'}} |
| 34 | } |
| 35 | |
Douglas Gregor | e761230 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 36 | // Check for private redeclarations of public entities. |
| 37 | template<typename T> |
Douglas Gregor | 2ccd89c | 2011-12-20 18:11:52 +0000 | [diff] [blame] | 38 | class public_class_template; |
Douglas Gregor | e761230 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 39 | |
| 40 | template<typename T> |
Douglas Gregor | 2ccd89c | 2011-12-20 18:11:52 +0000 | [diff] [blame] | 41 | __module_private__ class public_class_template; |
Douglas Gregor | e761230 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 42 | |
| 43 | |
Douglas Gregor | 2ccd89c | 2011-12-20 18:11:52 +0000 | [diff] [blame] | 44 | typedef int public_typedef; |
| 45 | typedef __module_private__ int public_typedef; |
Douglas Gregor | e761230 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 46 | |
Douglas Gregor | 2ccd89c | 2011-12-20 18:11:52 +0000 | [diff] [blame] | 47 | extern int public_var; |
| 48 | extern __module_private__ int public_var; |
Douglas Gregor | e761230 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 49 | |
Douglas Gregor | 2ccd89c | 2011-12-20 18:11:52 +0000 | [diff] [blame] | 50 | void public_func(); |
| 51 | __module_private__ void public_func(); |
Douglas Gregor | e761230 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 52 | |
| 53 | template<typename T> |
Douglas Gregor | 2ccd89c | 2011-12-20 18:11:52 +0000 | [diff] [blame] | 54 | void public_func_template(); |
Douglas Gregor | e761230 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 55 | template<typename T> |
Douglas Gregor | 2ccd89c | 2011-12-20 18:11:52 +0000 | [diff] [blame] | 56 | __module_private__ void public_func_template(); |
Douglas Gregor | e761230 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 57 | |
Douglas Gregor | 2ccd89c | 2011-12-20 18:11:52 +0000 | [diff] [blame] | 58 | struct public_struct; |
| 59 | __module_private__ struct public_struct; |
Douglas Gregor | e761230 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 60 | |
Douglas Gregor | d023aec | 2011-09-09 20:53:38 +0000 | [diff] [blame] | 61 | // Check for attempts to make specializations private |
| 62 | template<> __module_private__ void public_func_template<int>(); // expected-error{{template specialization cannot be declared __module_private__}} |
| 63 | |
| 64 | template<typename T> |
| 65 | struct public_class { |
| 66 | struct inner_struct; |
| 67 | static int static_var; |
Douglas Gregor | 6274d30 | 2011-09-09 21:14:29 +0000 | [diff] [blame] | 68 | |
Douglas Gregor | f3a762a | 2011-09-12 15:48:15 +0000 | [diff] [blame] | 69 | friend __module_private__ void public_func_friend(); |
| 70 | friend __module_private__ struct public_struct_friend; |
Douglas Gregor | d023aec | 2011-09-09 20:53:38 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | template<> __module_private__ struct public_class<int>::inner_struct { }; // expected-error{{member specialization cannot be declared __module_private__}} |
| 74 | template<> __module_private__ int public_class<int>::static_var = 17; // expected-error{{member specialization cannot be declared __module_private__}} |
| 75 | |
| 76 | template<> |
| 77 | __module_private__ struct public_class<float> { }; // expected-error{{template specialization cannot be declared __module_private__}} |
| 78 | |
| 79 | template<typename T> |
| 80 | __module_private__ struct public_class<T *> { }; // expected-error{{partial specialization cannot be declared __module_private__}} |
Douglas Gregor | e761230 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 81 | |
Douglas Gregor | e389585 | 2011-09-12 18:37:38 +0000 | [diff] [blame] | 82 | // Check for attempts to make parameters and variables with automatic |
| 83 | // storage module-private. |
| 84 | |
| 85 | void local_var_private(__module_private__ int param) { // expected-error{{parameter 'param' cannot be declared __module_private__}} |
| 86 | __module_private__ struct Local { int x, y; } local; //expected-error{{local variable 'local' cannot be declared __module_private__}} |
| 87 | |
| 88 | __module_private__ struct OtherLocal { int x; }; // expected-error{{local struct cannot be declared __module_private__}} |
| 89 | |
| 90 | typedef __module_private__ int local_typedef; // expected-error{{typedef 'local_typedef' cannot be declared __module_private__}} |
| 91 | } |
Douglas Gregor | fe522c2 | 2011-09-13 15:37:05 +0000 | [diff] [blame] | 92 | |
| 93 | // Check struct size |
| 94 | struct LikeVisibleStruct { |
| 95 | int field; |
| 96 | virtual void setField(int f); |
| 97 | }; |
| 98 | |
| 99 | int check_struct_size[sizeof(VisibleStruct) == sizeof(LikeVisibleStruct)? 1 : -1]; |