From: Douglas Gregor Date: Tue, 26 Jul 2011 14:53:44 +0000 (+0000) Subject: Objective-C++ ARC: When performing template argument deduction for a X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=da8b24961acfbeff47f585109b7559ba60e574cb;p=clang 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 . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136078 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index 888d3bee5f..824b9d9abb 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -1017,6 +1017,17 @@ DeduceTemplateArguments(Sema &S, if (ParamQs.hasObjCLifetime()) 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(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. diff --git a/test/SemaObjCXX/arc-templates.mm b/test/SemaObjCXX/arc-templates.mm index fa4e0a7776..7b0e6472c7 100644 --- a/test/SemaObjCXX/arc-templates.mm +++ b/test/SemaObjCXX/arc-templates.mm @@ -252,3 +252,17 @@ void test_qual_vs_unqual_a() { 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 float& f(T&); + template int& f(__strong T&); + template double& f(__weak T&); + + void test_f(A* ap) { + float &fr = (f)(ap); + } +}