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 |
| 4 | // RUN: %clang_cc1 -I %t %s -verify |
| 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 | } |
| 43 | #else |
| 44 | __import_module__ left; |
| 45 | __import_module__ right; |
| 46 | |
| 47 | void test() { |
| 48 | int &ir = f0(1.0); // okay: f0() from 'right' is not visible |
| 49 | } |
| 50 | |
| 51 | int test_broken() { |
| 52 | HiddenStruct hidden; // expected-error{{use of undeclared identifier 'HiddenStruct'}} |
| 53 | |
| 54 | Integer i; // expected-error{{use of undeclared identifier 'Integer'}} |
| 55 | |
| 56 | int *ip = 0; |
| 57 | f1(ip); // expected-error{{use of undeclared identifier 'f1'}} |
| 58 | |
| 59 | vector<int> vec; // expected-error{{use of undeclared identifier 'vector'}} \ |
| 60 | // expected-error{{expected '(' for function-style cast or type construction}} \ |
| 61 | // expected-error{{use of undeclared identifier 'vec'}} |
| 62 | |
| 63 | return hidden_var; // expected-error{{use of undeclared identifier 'hidden_var'}} |
| 64 | } |
| 65 | |
Douglas Gregor | e761230 | 2011-09-09 19:05:14 +0000 | [diff] [blame^] | 66 | // Check for private redeclarations of public entities. |
| 67 | template<typename T> |
| 68 | class public_class_template; // expected-note{{previous declaration is here}} |
| 69 | |
| 70 | template<typename T> |
| 71 | __module_private__ class public_class_template; // expected-error{{__module_private__ declaration of 'public_class_template' follows public declaration}} |
| 72 | |
| 73 | |
| 74 | typedef int public_typedef; // expected-note{{previous declaration is here}} |
| 75 | typedef __module_private__ int public_typedef; // expected-error{{__module_private__ declaration of 'public_typedef' follows public declaration}} |
| 76 | |
| 77 | extern int public_var; // expected-note{{previous declaration is here}} |
| 78 | extern __module_private__ int public_var; // expected-error{{__module_private__ declaration of 'public_var' follows public declaration}} |
| 79 | |
| 80 | void public_func(); // expected-note{{previous declaration is here}} |
| 81 | __module_private__ void public_func(); // expected-error{{__module_private__ declaration of 'public_func' follows public declaration}} |
| 82 | |
| 83 | template<typename T> |
| 84 | void public_func_template(); // expected-note{{previous declaration is here}} |
| 85 | template<typename T> |
| 86 | __module_private__ void public_func_template(); // expected-error{{__module_private__ declaration of 'public_func_template' follows public declaration}} |
| 87 | |
| 88 | struct public_struct; // expected-note{{previous declaration is here}} |
| 89 | __module_private__ struct public_struct; // expected-error{{__module_private__ declaration of 'public_struct' follows public declaration}} |
| 90 | |
| 91 | |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 92 | #endif |