]> granicus.if.org Git - clang/commitdiff
When performing the deduced/actual argument type check for C++
authorDouglas Gregor <dgregor@apple.com>
Wed, 18 Jul 2012 00:14:59 +0000 (00:14 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 18 Jul 2012 00:14:59 +0000 (00:14 +0000)
[temp.deduct.call]p4 under Objective-C++ ARC, make sure to adjust the
qualifiers to introduce the implicit strong lifetime when
needed. Fixes <rdar://problem/11825671>.

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

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

index dcf878115eefd21d019e2925ade58cfef0d31517..9500ec3219d4f0e613d63a326e529b8df52197fa 100644 (file)
@@ -2436,6 +2436,16 @@ CheckOriginalCallArgDeduction(Sema &S, Sema::OriginalCallArg OriginalArg,
     
     Qualifiers AQuals = A.getQualifiers();
     Qualifiers DeducedAQuals = DeducedA.getQualifiers();
+
+    // Under Objective-C++ ARC, the deduced type may have implicitly been
+    // given strong lifetime. If so, update the original qualifiers to
+    // include this strong lifetime.
+    if (S.getLangOpts().ObjCAutoRefCount &&
+        DeducedAQuals.getObjCLifetime() == Qualifiers::OCL_Strong &&
+        AQuals.getObjCLifetime() == Qualifiers::OCL_None) {
+      AQuals.setObjCLifetime(Qualifiers::OCL_Strong);
+    }
+
     if (AQuals == DeducedAQuals) {
       // Qualifiers match; there's nothing to do.
     } else if (!DeducedAQuals.compatiblyIncludes(AQuals)) {
index 9eca84648f6a6545d8e77cf3d63de17e349f66f2..80092729d34ec10af4b313a6fa42ad3ab119c32f 100644 (file)
@@ -3,6 +3,8 @@
 @interface A
 @end
 
+@class NSString;
+
 template<typename T, typename U>
 struct is_same {
   static const bool value = false;
@@ -266,3 +268,18 @@ namespace rdar9828157 {
     float &fr = (f)(ap);  
   }
 }
+
+namespace rdar10862386 {
+  // More deduction with lifetime qualifiers.
+  template <typename T>
+  int testing(const T &) {
+      return 1;
+  }
+
+  void test() {
+     testing(1);
+      testing("hi");
+      testing<NSString *>(@"hi");
+      testing(@"hi");
+ }
+}