]> granicus.if.org Git - clang/commitdiff
Objective-C++ ARC: When performing template argument deduction for a
authorDouglas Gregor <dgregor@apple.com>
Tue, 26 Jul 2011 14:53:44 +0000 (14:53 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 26 Jul 2011 14:53:44 +0000 (14:53 +0000)
lifetime-qualified template parameter, ensure that the deduced
template argument is a lifetime type. Fixes <rdar://problem/9828157>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136078 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateDeduction.cpp
test/SemaObjCXX/arc-templates.mm

index 888d3bee5f9727d1034e3c493085f4dec827d401..824b9d9abb8e62a0d2716869a6ccb029a72da007 100644 (file)
@@ -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<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.
index fa4e0a7776427005ad49a24118d0d783bc784e29..7b0e6472c7fe987807b5301666208b43087740bc 100644 (file)
@@ -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<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);  
+  }
+}