From 92d1387ca9a1b2becdf7d72e0111872cff135197 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Thu, 17 Jan 2013 23:59:28 +0000 Subject: [PATCH] One can override an Objective-C ARC ownership qualifier that came from a template parameter; make that also include one that came from 'auto'. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172770 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/TreeTransform.h | 10 ++++++++++ test/SemaObjCXX/arc-0x.mm | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 2091cffc83..bacf6d5d9b 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -3365,6 +3365,7 @@ TreeTransform::TransformQualifiedType(TypeLocBuilder &TLB, // Objective-C ARC: // A lifetime qualifier applied to a substituted template parameter // overrides the lifetime qualifier from the template argument. + const AutoType *AutoTy; if (const SubstTemplateTypeParmType *SubstTypeParam = dyn_cast(Result)) { QualType Replacement = SubstTypeParam->getReplacementType(); @@ -3377,6 +3378,15 @@ TreeTransform::TransformQualifiedType(TypeLocBuilder &TLB, SubstTypeParam->getReplacedParameter(), Replacement); TLB.TypeWasModifiedSafely(Result); + } else if ((AutoTy = dyn_cast(Result)) && AutoTy->isDeduced()) { + // 'auto' types behave the same way as template parameters. + QualType Deduced = AutoTy->getDeducedType(); + Qualifiers Qs = Deduced.getQualifiers(); + Qs.removeObjCLifetime(); + Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), + Qs); + Result = SemaRef.Context.getAutoType(Deduced); + TLB.TypeWasModifiedSafely(Result); } else { // Otherwise, complain about the addition of a qualifier to an // already-qualified type. diff --git a/test/SemaObjCXX/arc-0x.mm b/test/SemaObjCXX/arc-0x.mm index 43f6671ac2..391fc47f34 100644 --- a/test/SemaObjCXX/arc-0x.mm +++ b/test/SemaObjCXX/arc-0x.mm @@ -93,3 +93,11 @@ typedef __builtin_va_list va_list; __builtin_va_arg(args, id); } @end + +namespace rdar12078752 { + void f() { + NSObject* o =0; + __autoreleasing decltype(o) o2 = o; + __autoreleasing auto o3 = o; + } +} -- 2.40.0