Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 1 | // 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 Gregor | 9a6da69 | 2011-09-12 20:41:59 +0000 | [diff] [blame] | 4 | // RUN: %clang_cc1 -fmodule-cache-path %t %s -verify |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 5 | |
| 6 | #if defined(MODULE_LEFT) |
| 7 | |
Douglas Gregor | 6311d2b | 2011-09-09 18:32:39 +0000 | [diff] [blame] | 8 | __module_private__ struct HiddenStruct; |
| 9 | |
| 10 | struct HiddenStruct { |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 11 | }; |
| 12 | |
| 13 | |
| 14 | int &f0(int); |
| 15 | |
| 16 | template<typename T> |
| 17 | __module_private__ void f1(T*); |
| 18 | |
| 19 | template<typename T> |
Douglas Gregor | 6311d2b | 2011-09-09 18:32:39 +0000 | [diff] [blame] | 20 | void f1(T*); |
| 21 | |
| 22 | template<typename T> |
| 23 | __module_private__ class vector; |
| 24 | |
| 25 | template<typename T> |
| 26 | class vector { |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | vector<float> vec_float; |
| 30 | |
| 31 | typedef __module_private__ int Integer; |
Douglas Gregor | 6311d2b | 2011-09-09 18:32:39 +0000 | [diff] [blame] | 32 | typedef int Integer; |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 33 | |
| 34 | #elif defined(MODULE_RIGHT) |
| 35 | __module_private__ double &f0(double); |
Douglas Gregor | 6311d2b | 2011-09-09 18:32:39 +0000 | [diff] [blame] | 36 | double &f0(double); |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 37 | |
| 38 | __module_private__ int hidden_var; |
| 39 | |
| 40 | inline void test_f0_in_right() { |
| 41 | double &dr = f0(hidden_var); |
| 42 | } |
Douglas Gregor | 591dc84 | 2011-09-12 16:11:24 +0000 | [diff] [blame] | 43 | |
| 44 | struct VisibleStruct { |
| 45 | __module_private__ int field; |
Douglas Gregor | fe522c2 | 2011-09-13 15:37:05 +0000 | [diff] [blame^] | 46 | __module_private__ virtual void setField(int f); |
Douglas Gregor | 591dc84 | 2011-09-12 16:11:24 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 49 | #else |
| 50 | __import_module__ left; |
| 51 | __import_module__ right; |
| 52 | |
| 53 | void test() { |
| 54 | int &ir = f0(1.0); // okay: f0() from 'right' is not visible |
| 55 | } |
| 56 | |
| 57 | int 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 Gregor | 591dc84 | 2011-09-12 16:11:24 +0000 | [diff] [blame] | 69 | 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 Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 73 | return hidden_var; // expected-error{{use of undeclared identifier 'hidden_var'}} |
| 74 | } |
| 75 | |
Douglas Gregor | e761230 | 2011-09-09 19:05:14 +0000 | [diff] [blame] | 76 | // Check for private redeclarations of public entities. |
| 77 | template<typename T> |
| 78 | class public_class_template; // expected-note{{previous declaration is here}} |
| 79 | |
| 80 | template<typename T> |
| 81 | __module_private__ class public_class_template; // expected-error{{__module_private__ declaration of 'public_class_template' follows public declaration}} |
| 82 | |
| 83 | |
| 84 | typedef int public_typedef; // expected-note{{previous declaration is here}} |
| 85 | typedef __module_private__ int public_typedef; // expected-error{{__module_private__ declaration of 'public_typedef' follows public declaration}} |
| 86 | |
| 87 | extern int public_var; // expected-note{{previous declaration is here}} |
| 88 | extern __module_private__ int public_var; // expected-error{{__module_private__ declaration of 'public_var' follows public declaration}} |
| 89 | |
| 90 | void 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 | |
| 93 | template<typename T> |
| 94 | void public_func_template(); // expected-note{{previous declaration is here}} |
| 95 | template<typename T> |
| 96 | __module_private__ void public_func_template(); // expected-error{{__module_private__ declaration of 'public_func_template' follows public declaration}} |
| 97 | |
| 98 | struct 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 Gregor | d023aec | 2011-09-09 20:53:38 +0000 | [diff] [blame] | 101 | // Check for attempts to make specializations private |
| 102 | template<> __module_private__ void public_func_template<int>(); // expected-error{{template specialization cannot be declared __module_private__}} |
| 103 | |
| 104 | template<typename T> |
| 105 | struct public_class { |
| 106 | struct inner_struct; |
| 107 | static int static_var; |
Douglas Gregor | 6274d30 | 2011-09-09 21:14:29 +0000 | [diff] [blame] | 108 | |
Douglas Gregor | f3a762a | 2011-09-12 15:48:15 +0000 | [diff] [blame] | 109 | friend __module_private__ void public_func_friend(); |
| 110 | friend __module_private__ struct public_struct_friend; |
Douglas Gregor | d023aec | 2011-09-09 20:53:38 +0000 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | template<> __module_private__ struct public_class<int>::inner_struct { }; // expected-error{{member specialization cannot be declared __module_private__}} |
| 114 | template<> __module_private__ int public_class<int>::static_var = 17; // expected-error{{member specialization cannot be declared __module_private__}} |
| 115 | |
| 116 | template<> |
| 117 | __module_private__ struct public_class<float> { }; // expected-error{{template specialization cannot be declared __module_private__}} |
| 118 | |
| 119 | template<typename T> |
| 120 | __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] | 121 | |
Douglas Gregor | e389585 | 2011-09-12 18:37:38 +0000 | [diff] [blame] | 122 | // Check for attempts to make parameters and variables with automatic |
| 123 | // storage module-private. |
| 124 | |
| 125 | void 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 Gregor | fe522c2 | 2011-09-13 15:37:05 +0000 | [diff] [blame^] | 132 | |
| 133 | // Check struct size |
| 134 | struct LikeVisibleStruct { |
| 135 | int field; |
| 136 | virtual void setField(int f); |
| 137 | }; |
| 138 | |
| 139 | int check_struct_size[sizeof(VisibleStruct) == sizeof(LikeVisibleStruct)? 1 : -1]; |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 140 | #endif |