aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-07-26 14:53:44 +0000
committerDouglas Gregor <dgregor@apple.com>2011-07-26 14:53:44 +0000
commitda8b24961acfbeff47f585109b7559ba60e574cb (patch)
tree4b20c2c17d9cd055a0da145ec8905457381c0baa
parent9f1210c3280104417a4ad30f0a00825ac8fa718a (diff)
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>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136078 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaTemplateDeduction.cpp11
-rw-r--r--test/SemaObjCXX/arc-templates.mm14
2 files changed, 25 insertions, 0 deletions
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
@@ -1018,6 +1018,17 @@ DeduceTemplateArguments(Sema &S,
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 &&
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<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);
+ }
+}