1f4a2713aSLionel Sambuc // RUN: rm -rf %t 2f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fmodules -x objective-c++ -fmodules-cache-path=%t -fmodule-name=module_private_left -emit-module %S/Inputs/module.map 3f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fmodules -x objective-c++ -fmodules-cache-path=%t -fmodule-name=module_private_right -emit-module %S/Inputs/module.map 4*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fmodules -x objective-c++ -fmodules-cache-path=%t -I %S/Inputs %s -verify 5f4a2713aSLionel Sambuc // FIXME: When we have a syntax for modules in C++, use that. 6f4a2713aSLionel Sambuc 7f4a2713aSLionel Sambuc @import module_private_left; 8f4a2713aSLionel Sambuc @import module_private_right; 9f4a2713aSLionel Sambuc test()10f4a2713aSLionel Sambucvoid test() { 11f4a2713aSLionel Sambuc int &ir = f0(1.0); // okay: f0() from 'right' is not visible 12f4a2713aSLionel Sambuc } 13f4a2713aSLionel Sambuc test_broken()14f4a2713aSLionel Sambucint test_broken() { 15f4a2713aSLionel Sambuc HiddenStruct hidden; // \ 16f4a2713aSLionel Sambuc // expected-error{{must use 'struct' tag to refer to type 'HiddenStruct' in this scope}} \ 17f4a2713aSLionel Sambuc // expected-error{{definition of 'struct HiddenStruct' must be imported}} 18f4a2713aSLionel Sambuc // expected-note@Inputs/module_private_left.h:3 {{previous definition is here}} 19f4a2713aSLionel Sambuc 20f4a2713aSLionel Sambuc Integer i; // expected-error{{unknown type name 'Integer'}} 21f4a2713aSLionel Sambuc 22f4a2713aSLionel Sambuc int *ip = 0; 23f4a2713aSLionel Sambuc f1(ip); // expected-error{{use of undeclared identifier 'f1'}} 24f4a2713aSLionel Sambuc 25f4a2713aSLionel Sambuc vector<int> vec; // expected-error{{use of undeclared identifier 'vector'}} \ 26f4a2713aSLionel Sambuc // expected-error{{expected '(' for function-style cast or type construction}} \ 27f4a2713aSLionel Sambuc // expected-error{{use of undeclared identifier 'vec'}} 28f4a2713aSLionel Sambuc 29f4a2713aSLionel Sambuc VisibleStruct vs; 30f4a2713aSLionel Sambuc vs.field = 0; // expected-error{{no member named 'field' in 'VisibleStruct'}} 31f4a2713aSLionel Sambuc vs.setField(1); // expected-error{{no member named 'setField' in 'VisibleStruct'}} 32f4a2713aSLionel Sambuc 33f4a2713aSLionel Sambuc return hidden_var; // expected-error{{use of undeclared identifier 'hidden_var'}} 34f4a2713aSLionel Sambuc } 35f4a2713aSLionel Sambuc 36f4a2713aSLionel Sambuc // Check for private redeclarations of public entities. 37f4a2713aSLionel Sambuc template<typename T> 38f4a2713aSLionel Sambuc class public_class_template; 39f4a2713aSLionel Sambuc 40f4a2713aSLionel Sambuc template<typename T> 41f4a2713aSLionel Sambuc __module_private__ class public_class_template; 42f4a2713aSLionel Sambuc 43f4a2713aSLionel Sambuc 44f4a2713aSLionel Sambuc typedef int public_typedef; 45f4a2713aSLionel Sambuc typedef __module_private__ int public_typedef; 46f4a2713aSLionel Sambuc 47f4a2713aSLionel Sambuc extern int public_var; 48f4a2713aSLionel Sambuc extern __module_private__ int public_var; 49f4a2713aSLionel Sambuc 50f4a2713aSLionel Sambuc void public_func(); 51f4a2713aSLionel Sambuc __module_private__ void public_func(); 52f4a2713aSLionel Sambuc 53f4a2713aSLionel Sambuc template<typename T> 54f4a2713aSLionel Sambuc void public_func_template(); 55f4a2713aSLionel Sambuc template<typename T> 56f4a2713aSLionel Sambuc __module_private__ void public_func_template(); 57f4a2713aSLionel Sambuc 58f4a2713aSLionel Sambuc struct public_struct; 59f4a2713aSLionel Sambuc __module_private__ struct public_struct; 60f4a2713aSLionel Sambuc 61f4a2713aSLionel Sambuc // Check for attempts to make specializations private 62f4a2713aSLionel Sambuc template<> __module_private__ void public_func_template<int>(); // expected-error{{template specialization cannot be declared __module_private__}} 63f4a2713aSLionel Sambuc 64f4a2713aSLionel Sambuc template<typename T> 65f4a2713aSLionel Sambuc struct public_class { 66f4a2713aSLionel Sambuc struct inner_struct; 67f4a2713aSLionel Sambuc static int static_var; 68f4a2713aSLionel Sambuc 69f4a2713aSLionel Sambuc friend __module_private__ void public_func_friend(); 70f4a2713aSLionel Sambuc friend __module_private__ struct public_struct_friend; 71f4a2713aSLionel Sambuc }; 72f4a2713aSLionel Sambuc 73f4a2713aSLionel Sambuc template<> __module_private__ struct public_class<int>::inner_struct { }; // expected-error{{member specialization cannot be declared __module_private__}} 74f4a2713aSLionel Sambuc template<> __module_private__ int public_class<int>::static_var = 17; // expected-error{{member specialization cannot be declared __module_private__}} 75f4a2713aSLionel Sambuc 76f4a2713aSLionel Sambuc template<> 77f4a2713aSLionel Sambuc __module_private__ struct public_class<float> { }; // expected-error{{template specialization cannot be declared __module_private__}} 78f4a2713aSLionel Sambuc 79f4a2713aSLionel Sambuc template<typename T> 80f4a2713aSLionel Sambuc __module_private__ struct public_class<T *> { }; // expected-error{{partial specialization cannot be declared __module_private__}} 81f4a2713aSLionel Sambuc 82f4a2713aSLionel Sambuc // Check for attempts to make parameters and variables with automatic 83f4a2713aSLionel Sambuc // storage module-private. 84f4a2713aSLionel Sambuc local_var_private(__module_private__ int param)85f4a2713aSLionel Sambucvoid local_var_private(__module_private__ int param) { // expected-error{{parameter 'param' cannot be declared __module_private__}} 86f4a2713aSLionel Sambuc __module_private__ struct Local { int x, y; } local; //expected-error{{local variable 'local' cannot be declared __module_private__}} 87f4a2713aSLionel Sambuc 88f4a2713aSLionel Sambuc __module_private__ struct OtherLocal { int x; }; // expected-error{{local struct cannot be declared __module_private__}} 89f4a2713aSLionel Sambuc 90f4a2713aSLionel Sambuc typedef __module_private__ int local_typedef; // expected-error{{typedef 'local_typedef' cannot be declared __module_private__}} 91f4a2713aSLionel Sambuc } 92f4a2713aSLionel Sambuc 93f4a2713aSLionel Sambuc // Check struct size 94f4a2713aSLionel Sambuc struct LikeVisibleStruct { 95f4a2713aSLionel Sambuc int field; 96f4a2713aSLionel Sambuc virtual void setField(int f); 97f4a2713aSLionel Sambuc }; 98f4a2713aSLionel Sambuc 99f4a2713aSLionel Sambuc int check_struct_size[sizeof(VisibleStruct) == sizeof(LikeVisibleStruct)? 1 : -1]; 100