r198343 - Objective-C ARC++: Prefer references to __strong/__weak over __unsafe_unretained.
Douglas Gregor
dgregor at apple.com
Thu Jan 2 11:42:03 PST 2014
Author: dgregor
Date: Thu Jan 2 13:42:02 2014
New Revision: 198343
URL: http://llvm.org/viewvc/llvm-project?rev=198343&view=rev
Log:
Objective-C ARC++: Prefer references to __strong/__weak over __unsafe_unretained.
Fixes <rdar://problem/15713945>.
Modified:
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/test/SemaObjCXX/arc-templates.mm
Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=198343&r1=198342&r2=198343&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Thu Jan 2 13:42:02 2014
@@ -981,6 +981,17 @@ DeduceTemplateArgumentsByTypeMatch(Sema
Comparison.Qualifiers = ParamMoreQualified;
else if (ArgQuals.isStrictSupersetOf(ParamQuals))
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);
}
Modified: cfe/trunk/test/SemaObjCXX/arc-templates.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/arc-templates.mm?rev=198343&r1=198342&r2=198343&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/arc-templates.mm (original)
+++ cfe/trunk/test/SemaObjCXX/arc-templates.mm Thu Jan 2 13:42:02 2014
@@ -302,3 +302,19 @@ namespace rdar14467941 {
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);
+ }
+}
More information about the cfe-commits
mailing list