blob: 849897f7333dff6c028e81ff35ff206dac1ce4d0 [file] [log] [blame]
Douglas Gregor8d267c52011-09-09 02:06:17 +00001// 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 Gregor6311d2b2011-09-09 18:32:39 +00008__module_private__ struct HiddenStruct;
9
10struct HiddenStruct {
Douglas Gregor8d267c52011-09-09 02:06:17 +000011};
12
13
14int &f0(int);
15
16template<typename T>
17__module_private__ void f1(T*);
18
19template<typename T>
Douglas Gregor6311d2b2011-09-09 18:32:39 +000020void f1(T*);
21
22template<typename T>
23__module_private__ class vector;
24
25template<typename T>
26class vector {
Douglas Gregor8d267c52011-09-09 02:06:17 +000027};
28
29vector<float> vec_float;
30
31typedef __module_private__ int Integer;
Douglas Gregor6311d2b2011-09-09 18:32:39 +000032typedef int Integer;
Douglas Gregor8d267c52011-09-09 02:06:17 +000033
34#elif defined(MODULE_RIGHT)
35__module_private__ double &f0(double);
Douglas Gregor6311d2b2011-09-09 18:32:39 +000036double &f0(double);
Douglas Gregor8d267c52011-09-09 02:06:17 +000037
38__module_private__ int hidden_var;
39
40inline void test_f0_in_right() {
41 double &dr = f0(hidden_var);
42}
43#else
44__import_module__ left;
45__import_module__ right;
46
47void test() {
48 int &ir = f0(1.0); // okay: f0() from 'right' is not visible
49}
50
51int 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 Gregore7612302011-09-09 19:05:14 +000066// Check for private redeclarations of public entities.
67template<typename T>
68class public_class_template; // expected-note{{previous declaration is here}}
69
70template<typename T>
71__module_private__ class public_class_template; // expected-error{{__module_private__ declaration of 'public_class_template' follows public declaration}}
72
73
74typedef int public_typedef; // expected-note{{previous declaration is here}}
75typedef __module_private__ int public_typedef; // expected-error{{__module_private__ declaration of 'public_typedef' follows public declaration}}
76
77extern int public_var; // expected-note{{previous declaration is here}}
78extern __module_private__ int public_var; // expected-error{{__module_private__ declaration of 'public_var' follows public declaration}}
79
80void 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
83template<typename T>
84void public_func_template(); // expected-note{{previous declaration is here}}
85template<typename T>
86__module_private__ void public_func_template(); // expected-error{{__module_private__ declaration of 'public_func_template' follows public declaration}}
87
88struct 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
Douglas Gregord023aec2011-09-09 20:53:38 +000091// Check for attempts to make specializations private
92template<> __module_private__ void public_func_template<int>(); // expected-error{{template specialization cannot be declared __module_private__}}
93
94template<typename T>
95struct public_class {
96 struct inner_struct;
97 static int static_var;
Douglas Gregor6274d302011-09-09 21:14:29 +000098
99 friend __module_private__ void public_func(); // expected-error{{friend cannot be declared __module_private__}}
100 friend __module_private__ struct public_struct; // expected-error{{friend cannot be declared __module_private__}}
Douglas Gregord023aec2011-09-09 20:53:38 +0000101};
102
103template<> __module_private__ struct public_class<int>::inner_struct { }; // expected-error{{member specialization cannot be declared __module_private__}}
104template<> __module_private__ int public_class<int>::static_var = 17; // expected-error{{member specialization cannot be declared __module_private__}}
105
106template<>
107__module_private__ struct public_class<float> { }; // expected-error{{template specialization cannot be declared __module_private__}}
108
109template<typename T>
110__module_private__ struct public_class<T *> { }; // expected-error{{partial specialization cannot be declared __module_private__}}
Douglas Gregore7612302011-09-09 19:05:14 +0000111
Douglas Gregor8d267c52011-09-09 02:06:17 +0000112#endif