2011-11-16 13:16:30 +08:00
|
|
|
// RUN: rm -rf %t
|
2015-06-16 08:08:24 +08:00
|
|
|
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x objective-c++ -fmodules-cache-path=%t -fmodule-name=module_private_left -emit-module %S/Inputs/module.map
|
|
|
|
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x objective-c++ -fmodules-cache-path=%t -fmodule-name=module_private_right -emit-module %S/Inputs/module.map
|
|
|
|
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -x objective-c++ -fmodules-cache-path=%t -I %S/Inputs %s -verify
|
2012-01-04 03:32:59 +08:00
|
|
|
// FIXME: When we have a syntax for modules in C++, use that.
|
2011-09-09 10:06:17 +08:00
|
|
|
|
2012-12-12 06:11:52 +08:00
|
|
|
@import module_private_left;
|
|
|
|
@import module_private_right;
|
2011-09-09 10:06:17 +08:00
|
|
|
|
|
|
|
void test() {
|
|
|
|
int &ir = f0(1.0); // okay: f0() from 'right' is not visible
|
|
|
|
}
|
|
|
|
|
|
|
|
int test_broken() {
|
[modules] Simplify and generalize the existing rule for finding hidden
declarations in redeclaration lookup. A declaration is now visible to
lookup if:
* It is visible (not in a module, or in an imported module), or
* We're doing redeclaration lookup and it's externally-visible, or
* We're doing typo correction and looking for unimported decls.
We now support multiple modules having different internal-linkage or no-linkage
definitions of the same name for all entities, not just for functions,
variables, and some typedefs. As previously, if multiple such entities are
visible, any attempt to use them will result in an ambiguity error.
This patch fixes the linkage calculation for a number of entities where we
previously didn't need to get it right (using-declarations, namespace aliases,
and so on). It also classifies enumerators as always having no linkage, which
is a slight deviation from the C++ standard's definition, but not an observable
change outside modules (this change is being discussed on the -core reflector
currently).
This also removes the prior special case for tag lookup, which made some cases
of this work, but also led to bizarre, bogus "must use 'struct' to refer to type
'Foo' in this scope" diagnostics in C++.
llvm-svn: 252960
2015-11-13 06:19:45 +08:00
|
|
|
HiddenStruct hidden; // expected-error{{unknown type name 'HiddenStruct'}}
|
2012-08-24 04:19:14 +08:00
|
|
|
Integer i; // expected-error{{unknown type name 'Integer'}}
|
2011-09-09 10:06:17 +08:00
|
|
|
|
|
|
|
int *ip = 0;
|
|
|
|
f1(ip); // expected-error{{use of undeclared identifier 'f1'}}
|
|
|
|
|
|
|
|
vector<int> vec; // expected-error{{use of undeclared identifier 'vector'}} \
|
|
|
|
// expected-error{{expected '(' for function-style cast or type construction}} \
|
|
|
|
// expected-error{{use of undeclared identifier 'vec'}}
|
|
|
|
|
2011-09-13 00:11:24 +08:00
|
|
|
VisibleStruct vs;
|
|
|
|
vs.field = 0; // expected-error{{no member named 'field' in 'VisibleStruct'}}
|
|
|
|
vs.setField(1); // expected-error{{no member named 'setField' in 'VisibleStruct'}}
|
|
|
|
|
2011-09-09 10:06:17 +08:00
|
|
|
return hidden_var; // expected-error{{use of undeclared identifier 'hidden_var'}}
|
|
|
|
}
|
|
|
|
|
2011-09-10 03:05:14 +08:00
|
|
|
// Check for private redeclarations of public entities.
|
|
|
|
template<typename T>
|
2011-12-21 02:11:52 +08:00
|
|
|
class public_class_template;
|
2011-09-10 03:05:14 +08:00
|
|
|
|
|
|
|
template<typename T>
|
2011-12-21 02:11:52 +08:00
|
|
|
__module_private__ class public_class_template;
|
2011-09-10 03:05:14 +08:00
|
|
|
|
|
|
|
|
2011-12-21 02:11:52 +08:00
|
|
|
typedef int public_typedef;
|
|
|
|
typedef __module_private__ int public_typedef;
|
2011-09-10 03:05:14 +08:00
|
|
|
|
2011-12-21 02:11:52 +08:00
|
|
|
extern int public_var;
|
|
|
|
extern __module_private__ int public_var;
|
2011-09-10 03:05:14 +08:00
|
|
|
|
2011-12-21 02:11:52 +08:00
|
|
|
void public_func();
|
|
|
|
__module_private__ void public_func();
|
2011-09-10 03:05:14 +08:00
|
|
|
|
|
|
|
template<typename T>
|
2011-12-21 02:11:52 +08:00
|
|
|
void public_func_template();
|
2011-09-10 03:05:14 +08:00
|
|
|
template<typename T>
|
2011-12-21 02:11:52 +08:00
|
|
|
__module_private__ void public_func_template();
|
2011-09-10 03:05:14 +08:00
|
|
|
|
2011-12-21 02:11:52 +08:00
|
|
|
struct public_struct;
|
|
|
|
__module_private__ struct public_struct;
|
2011-09-10 03:05:14 +08:00
|
|
|
|
2011-09-10 04:53:38 +08:00
|
|
|
// Check for attempts to make specializations private
|
|
|
|
template<> __module_private__ void public_func_template<int>(); // expected-error{{template specialization cannot be declared __module_private__}}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct public_class {
|
|
|
|
struct inner_struct;
|
|
|
|
static int static_var;
|
2011-09-10 05:14:29 +08:00
|
|
|
|
2011-09-12 23:48:15 +08:00
|
|
|
friend __module_private__ void public_func_friend();
|
|
|
|
friend __module_private__ struct public_struct_friend;
|
2011-09-10 04:53:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template<> __module_private__ struct public_class<int>::inner_struct { }; // expected-error{{member specialization cannot be declared __module_private__}}
|
|
|
|
template<> __module_private__ int public_class<int>::static_var = 17; // expected-error{{member specialization cannot be declared __module_private__}}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
__module_private__ struct public_class<float> { }; // expected-error{{template specialization cannot be declared __module_private__}}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
__module_private__ struct public_class<T *> { }; // expected-error{{partial specialization cannot be declared __module_private__}}
|
2011-09-10 03:05:14 +08:00
|
|
|
|
2011-09-13 02:37:38 +08:00
|
|
|
// Check for attempts to make parameters and variables with automatic
|
|
|
|
// storage module-private.
|
|
|
|
|
|
|
|
void local_var_private(__module_private__ int param) { // expected-error{{parameter 'param' cannot be declared __module_private__}}
|
|
|
|
__module_private__ struct Local { int x, y; } local; //expected-error{{local variable 'local' cannot be declared __module_private__}}
|
|
|
|
|
|
|
|
__module_private__ struct OtherLocal { int x; }; // expected-error{{local struct cannot be declared __module_private__}}
|
|
|
|
|
|
|
|
typedef __module_private__ int local_typedef; // expected-error{{typedef 'local_typedef' cannot be declared __module_private__}}
|
|
|
|
}
|
2011-09-13 23:37:05 +08:00
|
|
|
|
|
|
|
// Check struct size
|
|
|
|
struct LikeVisibleStruct {
|
|
|
|
int field;
|
|
|
|
virtual void setField(int f);
|
|
|
|
};
|
|
|
|
|
|
|
|
int check_struct_size[sizeof(VisibleStruct) == sizeof(LikeVisibleStruct)? 1 : -1];
|