Douglas Gregor | 84febf4 | 2011-11-16 05:16:30 +0000 | [diff] [blame] | 1 | // RUN: rm -rf %t |
Richard Smith | 47972af | 2015-06-16 00:08:24 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x objective-c++ -fmodules-cache-path=%t -fmodule-name=module_private_left -emit-module %S/Inputs/module.map |
| 3 | // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x objective-c++ -fmodules-cache-path=%t -fmodule-name=module_private_right -emit-module %S/Inputs/module.map |
| 4 | // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x objective-c++ -fmodules-cache-path=%t -I %S/Inputs %s -verify |
Douglas Gregor | da82e70 | 2012-01-03 19:32:59 +0000 | [diff] [blame] | 5 | // FIXME: When we have a syntax for modules in C++, use that. |
Douglas Gregor | 26701a4 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 6 | |
Douglas Gregor | c50d492 | 2012-12-11 22:11:52 +0000 | [diff] [blame] | 7 | @import module_private_left; |
| 8 | @import module_private_right; |
Douglas Gregor | 26701a4 | 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 | 97135cc | 2015-11-12 22:19:45 +0000 | [diff] [blame] | 15 | HiddenStruct hidden; // expected-error{{unknown type name 'HiddenStruct'}} |
Richard Smith | 7aed66b | 2012-08-23 20:19:14 +0000 | [diff] [blame] | 16 | Integer i; // expected-error{{unknown type name 'Integer'}} |
Douglas Gregor | 26701a4 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 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 Gregor | 3baa670 | 2011-09-12 16:11:24 +0000 | [diff] [blame] | 25 | 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 Gregor | 26701a4 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 29 | return hidden_var; // expected-error{{use of undeclared identifier 'hidden_var'}} |
| 30 | } |
| 31 | |
Douglas Gregor | 2820e69 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 32 | // Check for private redeclarations of public entities. |
| 33 | template<typename T> |
Douglas Gregor | 21823bf | 2011-12-20 18:11:52 +0000 | [diff] [blame] | 34 | class public_class_template; |
Douglas Gregor | 2820e69 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 35 | |
| 36 | template<typename T> |
Douglas Gregor | 21823bf | 2011-12-20 18:11:52 +0000 | [diff] [blame] | 37 | __module_private__ class public_class_template; |
Douglas Gregor | 2820e69 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 38 | |
| 39 | |
Douglas Gregor | 21823bf | 2011-12-20 18:11:52 +0000 | [diff] [blame] | 40 | typedef int public_typedef; |
| 41 | typedef __module_private__ int public_typedef; |
Douglas Gregor | 2820e69 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 42 | |
Douglas Gregor | 21823bf | 2011-12-20 18:11:52 +0000 | [diff] [blame] | 43 | extern int public_var; |
| 44 | extern __module_private__ int public_var; |
Douglas Gregor | 2820e69 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 45 | |
Douglas Gregor | 21823bf | 2011-12-20 18:11:52 +0000 | [diff] [blame] | 46 | void public_func(); |
| 47 | __module_private__ void public_func(); |
Douglas Gregor | 2820e69 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 48 | |
| 49 | template<typename T> |
Douglas Gregor | 21823bf | 2011-12-20 18:11:52 +0000 | [diff] [blame] | 50 | void public_func_template(); |
Douglas Gregor | 2820e69 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 51 | template<typename T> |
Douglas Gregor | 21823bf | 2011-12-20 18:11:52 +0000 | [diff] [blame] | 52 | __module_private__ void public_func_template(); |
Douglas Gregor | 2820e69 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 53 | |
Douglas Gregor | 21823bf | 2011-12-20 18:11:52 +0000 | [diff] [blame] | 54 | struct public_struct; |
| 55 | __module_private__ struct public_struct; |
Douglas Gregor | 2820e69 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 56 | |
Douglas Gregor | 3c7cd6a | 2011-09-09 20:53:38 +0000 | [diff] [blame] | 57 | // Check for attempts to make specializations private |
| 58 | template<> __module_private__ void public_func_template<int>(); // expected-error{{template specialization cannot be declared __module_private__}} |
| 59 | |
| 60 | template<typename T> |
| 61 | struct public_class { |
| 62 | struct inner_struct; |
| 63 | static int static_var; |
Douglas Gregor | 6422642 | 2011-09-09 21:14:29 +0000 | [diff] [blame] | 64 | |
Douglas Gregor | fc33bcf | 2011-09-12 15:48:15 +0000 | [diff] [blame] | 65 | friend __module_private__ void public_func_friend(); |
| 66 | friend __module_private__ struct public_struct_friend; |
Douglas Gregor | 3c7cd6a | 2011-09-09 20:53:38 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | template<> __module_private__ struct public_class<int>::inner_struct { }; // expected-error{{member specialization cannot be declared __module_private__}} |
| 70 | template<> __module_private__ int public_class<int>::static_var = 17; // expected-error{{member specialization cannot be declared __module_private__}} |
| 71 | |
| 72 | template<> |
| 73 | __module_private__ struct public_class<float> { }; // expected-error{{template specialization cannot be declared __module_private__}} |
| 74 | |
| 75 | template<typename T> |
| 76 | __module_private__ struct public_class<T *> { }; // expected-error{{partial specialization cannot be declared __module_private__}} |
Douglas Gregor | 2820e69 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 77 | |
Douglas Gregor | 4186681 | 2011-09-12 18:37:38 +0000 | [diff] [blame] | 78 | // Check for attempts to make parameters and variables with automatic |
| 79 | // storage module-private. |
| 80 | |
| 81 | void 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 Gregor | a057a58 | 2011-09-13 15:37:05 +0000 | [diff] [blame] | 88 | |
| 89 | // Check struct size |
| 90 | struct LikeVisibleStruct { |
| 91 | int field; |
| 92 | virtual void setField(int f); |
| 93 | }; |
| 94 | |
| 95 | int check_struct_size[sizeof(VisibleStruct) == sizeof(LikeVisibleStruct)? 1 : -1]; |