142583320cf7977fd474572b9fe78e13eaf45fb8fDouglas Gregor// RUN: rm -rf %t
2953a61f26bf79932b9699b09add4c388764de170Douglas Gregor// RUN: %clang_cc1 -fmodules -x objective-c++ -fmodules-cache-path=%t -fmodule-name=module_private_left -emit-module %S/Inputs/module.map
3953a61f26bf79932b9699b09add4c388764de170Douglas Gregor// RUN: %clang_cc1 -fmodules -x objective-c++ -fmodules-cache-path=%t -fmodule-name=module_private_right -emit-module %S/Inputs/module.map
4651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// RUN: %clang_cc1 -fmodules -x objective-c++ -fmodules-cache-path=%t -I %S/Inputs %s -verify
5c13a34b690d2dc2a03c2fea75a0a1438636c19ceDouglas Gregor// FIXME: When we have a syntax for modules in C++, use that.
68d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor
71b257afbae854c6817f26b7d61c4fed8ff7aebadDouglas Gregor@import module_private_left;
81b257afbae854c6817f26b7d61c4fed8ff7aebadDouglas Gregor@import module_private_right;
98d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor
108d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregorvoid test() {
118d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor  int &ir = f0(1.0); // okay: f0() from 'right' is not visible
128d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor}
138d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor
148d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregorint test_broken() {
1540b2e19cae6ab85407856c70f76278f9efbeeb7cRichard Smith  HiddenStruct hidden; // \
1640b2e19cae6ab85407856c70f76278f9efbeeb7cRichard Smith  // expected-error{{must use 'struct' tag to refer to type 'HiddenStruct' in this scope}} \
1740b2e19cae6ab85407856c70f76278f9efbeeb7cRichard Smith  // expected-error{{definition of 'struct HiddenStruct' must be imported}}
18b42f200777a66b98989160bf3987ce431540a584Andy Gibbs  // expected-note@Inputs/module_private_left.h:3 {{previous definition is here}}
198d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor
2040b2e19cae6ab85407856c70f76278f9efbeeb7cRichard Smith  Integer i; // expected-error{{unknown type name 'Integer'}}
218d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor
228d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor  int *ip = 0;
238d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor  f1(ip); // expected-error{{use of undeclared identifier 'f1'}}
248d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor
258d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor  vector<int> vec; // expected-error{{use of undeclared identifier 'vector'}} \
268d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor  // expected-error{{expected '(' for function-style cast or type construction}} \
278d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor  // expected-error{{use of undeclared identifier 'vec'}}
288d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor
29591dc84101228dc391fca05193be5870ec661edcDouglas Gregor  VisibleStruct vs;
30591dc84101228dc391fca05193be5870ec661edcDouglas Gregor  vs.field = 0; // expected-error{{no member named 'field' in 'VisibleStruct'}}
31591dc84101228dc391fca05193be5870ec661edcDouglas Gregor  vs.setField(1); // expected-error{{no member named 'setField' in 'VisibleStruct'}}
32591dc84101228dc391fca05193be5870ec661edcDouglas Gregor
338d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor  return hidden_var; // expected-error{{use of undeclared identifier 'hidden_var'}}
348d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor}
358d267c57afb3af418ed5281b7a9bb4555d701a82Douglas Gregor
36e761230ae3751b525cadd8066c74ec278ee4ef57Douglas Gregor// Check for private redeclarations of public entities.
37e761230ae3751b525cadd8066c74ec278ee4ef57Douglas Gregortemplate<typename T>
382ccd89cff3f1c18b48f649240302446a7dae28b9Douglas Gregorclass public_class_template;
39e761230ae3751b525cadd8066c74ec278ee4ef57Douglas Gregor
40e761230ae3751b525cadd8066c74ec278ee4ef57Douglas Gregortemplate<typename T>
412ccd89cff3f1c18b48f649240302446a7dae28b9Douglas Gregor__module_private__ class public_class_template;
42e761230ae3751b525cadd8066c74ec278ee4ef57Douglas Gregor
43e761230ae3751b525cadd8066c74ec278ee4ef57Douglas Gregor
442ccd89cff3f1c18b48f649240302446a7dae28b9Douglas Gregortypedef int public_typedef;
452ccd89cff3f1c18b48f649240302446a7dae28b9Douglas Gregortypedef __module_private__ int public_typedef;
46e761230ae3751b525cadd8066c74ec278ee4ef57Douglas Gregor
472ccd89cff3f1c18b48f649240302446a7dae28b9Douglas Gregorextern int public_var;
482ccd89cff3f1c18b48f649240302446a7dae28b9Douglas Gregorextern __module_private__ int public_var;
49e761230ae3751b525cadd8066c74ec278ee4ef57Douglas Gregor
502ccd89cff3f1c18b48f649240302446a7dae28b9Douglas Gregorvoid public_func();
512ccd89cff3f1c18b48f649240302446a7dae28b9Douglas Gregor__module_private__ void public_func();
52e761230ae3751b525cadd8066c74ec278ee4ef57Douglas Gregor
53e761230ae3751b525cadd8066c74ec278ee4ef57Douglas Gregortemplate<typename T>
542ccd89cff3f1c18b48f649240302446a7dae28b9Douglas Gregorvoid public_func_template();
55e761230ae3751b525cadd8066c74ec278ee4ef57Douglas Gregortemplate<typename T>
562ccd89cff3f1c18b48f649240302446a7dae28b9Douglas Gregor__module_private__ void public_func_template();
57e761230ae3751b525cadd8066c74ec278ee4ef57Douglas Gregor
582ccd89cff3f1c18b48f649240302446a7dae28b9Douglas Gregorstruct public_struct;
592ccd89cff3f1c18b48f649240302446a7dae28b9Douglas Gregor__module_private__ struct public_struct;
60e761230ae3751b525cadd8066c74ec278ee4ef57Douglas Gregor
61d023aec8907831a18d3514a95b843a7ee06b6b5eDouglas Gregor// Check for attempts to make specializations private
62d023aec8907831a18d3514a95b843a7ee06b6b5eDouglas Gregortemplate<> __module_private__ void public_func_template<int>(); // expected-error{{template specialization cannot be declared __module_private__}}
63d023aec8907831a18d3514a95b843a7ee06b6b5eDouglas Gregor
64d023aec8907831a18d3514a95b843a7ee06b6b5eDouglas Gregortemplate<typename T>
65d023aec8907831a18d3514a95b843a7ee06b6b5eDouglas Gregorstruct public_class {
66d023aec8907831a18d3514a95b843a7ee06b6b5eDouglas Gregor  struct inner_struct;
67d023aec8907831a18d3514a95b843a7ee06b6b5eDouglas Gregor  static int static_var;
686274d30d77870393d83a404dd223b8005f2b8cd5Douglas Gregor
69f3a762a8de396af471f35b77f6897989867c898eDouglas Gregor  friend __module_private__ void public_func_friend();
70f3a762a8de396af471f35b77f6897989867c898eDouglas Gregor  friend __module_private__ struct public_struct_friend;
71d023aec8907831a18d3514a95b843a7ee06b6b5eDouglas Gregor};
72d023aec8907831a18d3514a95b843a7ee06b6b5eDouglas Gregor
73d023aec8907831a18d3514a95b843a7ee06b6b5eDouglas Gregortemplate<> __module_private__ struct public_class<int>::inner_struct { }; // expected-error{{member specialization cannot be declared __module_private__}}
74d023aec8907831a18d3514a95b843a7ee06b6b5eDouglas Gregortemplate<> __module_private__ int public_class<int>::static_var = 17; // expected-error{{member specialization cannot be declared __module_private__}}
75d023aec8907831a18d3514a95b843a7ee06b6b5eDouglas Gregor
76d023aec8907831a18d3514a95b843a7ee06b6b5eDouglas Gregortemplate<>
77d023aec8907831a18d3514a95b843a7ee06b6b5eDouglas Gregor__module_private__ struct public_class<float> { }; // expected-error{{template specialization cannot be declared __module_private__}}
78d023aec8907831a18d3514a95b843a7ee06b6b5eDouglas Gregor
79d023aec8907831a18d3514a95b843a7ee06b6b5eDouglas Gregortemplate<typename T>
80d023aec8907831a18d3514a95b843a7ee06b6b5eDouglas Gregor__module_private__ struct public_class<T *> { }; // expected-error{{partial specialization cannot be declared __module_private__}}
81e761230ae3751b525cadd8066c74ec278ee4ef57Douglas Gregor
82e389585f8a40f80004d3b98b99f3980305ef78a0Douglas Gregor// Check for attempts to make parameters and variables with automatic
83e389585f8a40f80004d3b98b99f3980305ef78a0Douglas Gregor// storage module-private.
84e389585f8a40f80004d3b98b99f3980305ef78a0Douglas Gregor
85e389585f8a40f80004d3b98b99f3980305ef78a0Douglas Gregorvoid local_var_private(__module_private__ int param) { // expected-error{{parameter 'param' cannot be declared __module_private__}}
86e389585f8a40f80004d3b98b99f3980305ef78a0Douglas Gregor  __module_private__ struct Local { int x, y; } local; //expected-error{{local variable 'local' cannot be declared __module_private__}}
87e389585f8a40f80004d3b98b99f3980305ef78a0Douglas Gregor
88e389585f8a40f80004d3b98b99f3980305ef78a0Douglas Gregor  __module_private__ struct OtherLocal { int x; }; // expected-error{{local struct cannot be declared __module_private__}}
89e389585f8a40f80004d3b98b99f3980305ef78a0Douglas Gregor
90e389585f8a40f80004d3b98b99f3980305ef78a0Douglas Gregor  typedef __module_private__ int local_typedef; // expected-error{{typedef 'local_typedef' cannot be declared __module_private__}}
91e389585f8a40f80004d3b98b99f3980305ef78a0Douglas Gregor}
92fe522c20516878927e4f90a2aeafeeba2ea31c71Douglas Gregor
93fe522c20516878927e4f90a2aeafeeba2ea31c71Douglas Gregor// Check struct size
94fe522c20516878927e4f90a2aeafeeba2ea31c71Douglas Gregorstruct LikeVisibleStruct {
95fe522c20516878927e4f90a2aeafeeba2ea31c71Douglas Gregor  int field;
96fe522c20516878927e4f90a2aeafeeba2ea31c71Douglas Gregor  virtual void setField(int f);
97fe522c20516878927e4f90a2aeafeeba2ea31c71Douglas Gregor};
98fe522c20516878927e4f90a2aeafeeba2ea31c71Douglas Gregor
99fe522c20516878927e4f90a2aeafeeba2ea31c71Douglas Gregorint check_struct_size[sizeof(VisibleStruct) == sizeof(LikeVisibleStruct)? 1 : -1];
100