diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-06-17 22:11:49 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-06-17 22:11:49 +0000 |
commit | e46db90c9aa00cbe1cbc6211ab4c5181ce287ce4 (patch) | |
tree | ff141edad4598f3c5fd6028ee6d0dd3446ed3950 /clang/test | |
parent | c662ec8bd33e6d81f9477c3a99751b64fd9a7be2 (diff) | |
download | bcm5719-llvm-e46db90c9aa00cbe1cbc6211ab4c5181ce287ce4.tar.gz bcm5719-llvm-e46db90c9aa00cbe1cbc6211ab4c5181ce287ce4.zip |
Objective-ARC++: infer template type arguments of
ownership-unqualified retainable object type as __strong. This allows
us to write, e.g.,
std::vector<id>
and we'll infer that the vector's element types have __strong
ownership semantics, which is far nicer than requiring:
std::vector<__strong id>
Note that we allow one to override the ownership qualifier of a
substituted template type parameter, e.g., given
template<typename T>
struct X {
typedef __weak T type;
};
X<id> is treated the same as X<__strong id>. At instantiation type,
the __weak in "__weak T" overrides the (inferred or specified)
__strong on the template argument type, so that we can still provide
metaprogramming transformations.
This is part of <rdar://problem/9595486>.
llvm-svn: 133303
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/SemaObjCXX/arc-templates.mm | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/clang/test/SemaObjCXX/arc-templates.mm b/clang/test/SemaObjCXX/arc-templates.mm index eeaed89876f..3711bd72df2 100644 --- a/clang/test/SemaObjCXX/arc-templates.mm +++ b/clang/test/SemaObjCXX/arc-templates.mm @@ -17,15 +17,13 @@ struct is_same<T, T> { // adjustments. template<typename T> struct X0 { - typedef T* pointer; // expected-error{{pointer to non-const type 'id' with no explicit lifetime}} \ - // expected-error{{pointer to non-const type 'A *' with no explicit lifetime}} - typedef T& reference; // expected-error{{reference to non-const type 'id' with no explicit lifetime}} \ - // expected-error{{reference to non-const type 'A *' with no explicit lifetime}} + typedef T* pointer; // okay: ends up being strong. + typedef T& reference; // okay: ends up being strong }; void test_X0() { - X0<id> x0id; // expected-note{{in instantiation of template class 'X0<id>' requested here}} - X0<A*> x0a; // expected-note{{in instantiation of template class 'X0<A *>' requested here}} + X0<id> x0id; + X0<A*> x0a; X0<__strong A*> x0sa; id __strong *ptr; @@ -34,6 +32,8 @@ void test_X0() { X0<__strong id>::reference ref = val; } +int check_infer_strong[is_same<id, __strong id>::value? 1 : -1]; + // Check template argument deduction (e.g., for specialization) using // lifetime qualifiers. template<typename T> @@ -58,6 +58,21 @@ struct make_strong_pointer { typedef __strong T *type; }; +template<typename T> +struct make_strong_pointer<__weak T> { + typedef __strong T *type; +}; + +template<typename T> +struct make_strong_pointer<__autoreleasing T> { + typedef __strong T *type; +}; + +template<typename T> +struct make_strong_pointer<__unsafe_unretained T> { + typedef __strong T *type; +}; + // Adding qualifiers int check_make_strong1[is_same<make_strong_pointer<id>::type, __strong id *>::value ? 1 : -1]; int check_make_strong2[is_same<make_strong_pointer<A*>::type, A* __strong *>::value ? 1 : -1]; @@ -68,7 +83,17 @@ int check_make_strong4[is_same<make_strong_pointer<__strong A*>::type, A* __stro // Adding nonsensical qualifiers. int check_make_strong5[is_same<make_strong_pointer<int>::type, int *>::value ? 1 : -1]; -int check_make_strong6[is_same<make_strong_pointer<__weak id>::type, __weak id *>::value ? 1 : -1]; +int check_make_strong6[is_same<make_strong_pointer<__weak id>::type, __strong id *>::value ? 1 : -1]; + +template<typename T> +struct make_weak { + typedef __weak T type; +}; + +int check_make_weak0[is_same<make_weak<id>::type, __weak id>::value? 1 : -1]; +int check_make_weak1[is_same<make_weak<__strong id>::type, __weak id>::value? 1 : -1]; +int check_make_weak2[is_same<make_weak<__autoreleasing id>::type, __weak id>::value? 1 : -1]; + // Check template argument deduction from function templates. template<typename T> struct identity { }; |