Objective-C ARC++: Prefer references to __strong/__weak over __unsafe_unretained.

Fixes <rdar://problem/15713945>.

llvm-svn: 198343
This commit is contained in:
Douglas Gregor 2014-01-02 19:42:02 +00:00
parent 8e6e6abf53
commit 6beabeed39
2 changed files with 27 additions and 0 deletions

View File

@ -981,6 +981,17 @@ DeduceTemplateArgumentsByTypeMatch(Sema &S,
Comparison.Qualifiers = ParamMoreQualified; Comparison.Qualifiers = ParamMoreQualified;
else if (ArgQuals.isStrictSupersetOf(ParamQuals)) else if (ArgQuals.isStrictSupersetOf(ParamQuals))
Comparison.Qualifiers = ArgMoreQualified; Comparison.Qualifiers = ArgMoreQualified;
else if (ArgQuals.getObjCLifetime() != ParamQuals.getObjCLifetime() &&
ArgQuals.withoutObjCLifetime()
== ParamQuals.withoutObjCLifetime()) {
// Prefer binding to non-__unsafe_autoretained parameters.
if (ArgQuals.getObjCLifetime() == Qualifiers::OCL_ExplicitNone &&
ParamQuals.getObjCLifetime())
Comparison.Qualifiers = ParamMoreQualified;
else if (ParamQuals.getObjCLifetime() == Qualifiers::OCL_ExplicitNone &&
ArgQuals.getObjCLifetime())
Comparison.Qualifiers = ArgMoreQualified;
}
RefParamComparisons->push_back(Comparison); RefParamComparisons->push_back(Comparison);
} }

View File

@ -302,3 +302,19 @@ namespace rdar14467941 {
float &fr2 = takePtr<A>(a); float &fr2 = takePtr<A>(a);
} }
} }
namespace rdar15713945 {
template <class T> int &f(__strong T &);
template <class T> float &f(__weak T &);
template <class T> double &f(__unsafe_unretained T &);
template <class T> char &f(T &);
void foo() {
__strong NSString * const strong = 0;
int &ir = (f)(strong);
__weak NSString * const weak = 0;
float &fr = (f)(weak);
__unsafe_unretained NSString * const unsafe = 0;
double &dr = (f)(unsafe);
}
}