[cfe-commits] r136078 - in /cfe/trunk: lib/Sema/SemaTemplateDeduction.cpp test/SemaObjCXX/arc-templates.mm
Douglas Gregor
dgregor at apple.com
Tue Jul 26 07:53:44 PDT 2011
Author: dgregor
Date: Tue Jul 26 09:53:44 2011
New Revision: 136078
URL: http://llvm.org/viewvc/llvm-project?rev=136078&view=rev
Log:
Objective-C++ ARC: When performing template argument deduction for a
lifetime-qualified template parameter, ensure that the deduced
template argument is a lifetime type. Fixes <rdar://problem/9828157>.
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=136078&r1=136077&r2=136078&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Tue Jul 26 09:53:44 2011
@@ -1018,6 +1018,17 @@
DeducedQs.removeObjCLifetime();
// Objective-C ARC:
+ // If template deduction would produce a lifetime qualifier on a type
+ // that is not a lifetime type, template argument deduction fails.
+ if (ParamQs.hasObjCLifetime() && !DeducedType->isObjCLifetimeType() &&
+ !DeducedType->isDependentType()) {
+ Info.Param = cast<TemplateTypeParmDecl>(TemplateParams->getParam(Index));
+ Info.FirstArg = TemplateArgument(Param);
+ Info.SecondArg = TemplateArgument(Arg);
+ return Sema::TDK_Underqualified;
+ }
+
+ // Objective-C ARC:
// If template deduction would produce an argument type with lifetime type
// but no lifetime qualifier, the __strong lifetime qualifier is inferred.
if (S.getLangOptions().ObjCAutoRefCount &&
Modified: cfe/trunk/test/SemaObjCXX/arc-templates.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/arc-templates.mm?rev=136078&r1=136077&r2=136078&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/arc-templates.mm (original)
+++ cfe/trunk/test/SemaObjCXX/arc-templates.mm Tue Jul 26 09:53:44 2011
@@ -252,3 +252,17 @@
float &fr3 = qual_vs_unqual_ref(*aap);
float &fr4 = qual_vs_unqual_ref(*uap);
}
+
+namespace rdar9828157 {
+ // Template argument deduction involving lifetime qualifiers and
+ // non-lifetime types.
+ class A { };
+
+ template<typename T> float& f(T&);
+ template<typename T> int& f(__strong T&);
+ template<typename T> double& f(__weak T&);
+
+ void test_f(A* ap) {
+ float &fr = (f)(ap);
+ }
+}
More information about the cfe-commits
mailing list