2011-12-15 00:03:29 +08:00
|
|
|
// RUN: rm -rf %t
|
Ensure that type definitions present in just-loaded modules are
visible.
The basic problem here is that a given translation unit can use
forward declarations to form pointers to a given type, say,
class X;
X *x;
and then import a module that includes a definition of X:
import XDef;
We will then fail when attempting to access a member of X, e.g.,
x->method()
because the AST reader did not know to look for a default of a class
named X within the new module.
This implementation is a bit of a C-centric hack, because the only
definitions that can have this property are enums, structs, unions,
Objective-C classes, and Objective-C protocols, and all of those are
either visible at the top-level or can't be defined later. Hence, we
can use the out-of-date-ness of the name and the identifier-update
mechanism to force the update.
In C++, we will not be so lucky, and will need a more advanced
solution, because the definitions could be in namespaces defined in
two different modules, e.g.,
// module 1
namespace N { struct X; }
// module 2
namespace N { struct X { /* ... */ }; }
One possible implementation here is for C++ to extend the information
associated with each identifier table to include the declaration IDs
of any definitions associated with that name, regardless of
context. We would have to eagerly load those definitions.
llvm-svn: 174794
2013-02-09 09:35:03 +08:00
|
|
|
// RUN: %clang_cc1 -fmodules -fobjc-arc -I %S/Inputs -fmodules-cache-path=%t %s -verify
|
2011-12-15 00:03:29 +08:00
|
|
|
|
2012-01-03 01:18:37 +08:00
|
|
|
|
2013-01-12 09:29:50 +08:00
|
|
|
// In other file: expected-note {{previous definition is here}}
|
2012-01-03 01:18:37 +08:00
|
|
|
|
Ensure that type definitions present in just-loaded modules are
visible.
The basic problem here is that a given translation unit can use
forward declarations to form pointers to a given type, say,
class X;
X *x;
and then import a module that includes a definition of X:
import XDef;
We will then fail when attempting to access a member of X, e.g.,
x->method()
because the AST reader did not know to look for a default of a class
named X within the new module.
This implementation is a bit of a C-centric hack, because the only
definitions that can have this property are enums, structs, unions,
Objective-C classes, and Objective-C protocols, and all of those are
either visible at the top-level or can't be defined later. Hence, we
can use the out-of-date-ness of the name and the identifier-update
mechanism to force the update.
In C++, we will not be so lucky, and will need a more advanced
solution, because the definitions could be in namespaces defined in
two different modules, e.g.,
// module 1
namespace N { struct X; }
// module 2
namespace N { struct X { /* ... */ }; }
One possible implementation here is for C++ to extend the information
associated with each identifier table to include the declaration IDs
of any definitions associated with that name, regardless of
context. We would have to eagerly load those definitions.
llvm-svn: 174794
2013-02-09 09:35:03 +08:00
|
|
|
@class Def;
|
|
|
|
Def *def;
|
|
|
|
class Def2;
|
|
|
|
Def2 *def2;
|
|
|
|
|
|
|
|
@interface Unrelated
|
|
|
|
- defMethod;
|
|
|
|
@end
|
|
|
|
|
2012-12-12 06:11:52 +08:00
|
|
|
@import decldef;
|
2011-12-15 00:03:29 +08:00
|
|
|
A *a1; // expected-error{{unknown type name 'A'}}
|
|
|
|
B *b1; // expected-error{{unknown type name 'B'}}
|
2012-12-12 06:11:52 +08:00
|
|
|
@import decldef.Decl;
|
2011-12-15 00:03:29 +08:00
|
|
|
|
2011-12-16 04:36:27 +08:00
|
|
|
A *a2;
|
2011-12-15 00:03:29 +08:00
|
|
|
B *b;
|
|
|
|
|
2012-01-03 01:18:37 +08:00
|
|
|
void testA(A *a) {
|
2013-01-12 09:29:50 +08:00
|
|
|
a->ivar = 17; // expected-error{{definition of 'A' must be imported from module 'decldef.Def' before it is required}}
|
2012-01-03 01:18:37 +08:00
|
|
|
}
|
|
|
|
|
2011-12-15 00:03:29 +08:00
|
|
|
void testB() {
|
2013-01-12 09:29:50 +08:00
|
|
|
B b; // Note: redundant error silenced
|
2011-12-15 00:03:29 +08:00
|
|
|
}
|
Ensure that type definitions present in just-loaded modules are
visible.
The basic problem here is that a given translation unit can use
forward declarations to form pointers to a given type, say,
class X;
X *x;
and then import a module that includes a definition of X:
import XDef;
We will then fail when attempting to access a member of X, e.g.,
x->method()
because the AST reader did not know to look for a default of a class
named X within the new module.
This implementation is a bit of a C-centric hack, because the only
definitions that can have this property are enums, structs, unions,
Objective-C classes, and Objective-C protocols, and all of those are
either visible at the top-level or can't be defined later. Hence, we
can use the out-of-date-ness of the name and the identifier-update
mechanism to force the update.
In C++, we will not be so lucky, and will need a more advanced
solution, because the definitions could be in namespaces defined in
two different modules, e.g.,
// module 1
namespace N { struct X; }
// module 2
namespace N { struct X { /* ... */ }; }
One possible implementation here is for C++ to extend the information
associated with each identifier table to include the declaration IDs
of any definitions associated with that name, regardless of
context. We would have to eagerly load those definitions.
llvm-svn: 174794
2013-02-09 09:35:03 +08:00
|
|
|
|
|
|
|
void testDef() {
|
|
|
|
[def defMethod];
|
|
|
|
}
|
|
|
|
|
|
|
|
void testDef2() {
|
|
|
|
def2->func();
|
|
|
|
}
|