From: Douglas Gregor Date: Fri, 14 Oct 2011 15:55:40 +0000 (+0000) Subject: Under ARC, merge the bit corresponding to the ns_returns_retained X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cb1c9c36b856ad24bd32ec673fb2490d9770ab5f;p=clang Under ARC, merge the bit corresponding to the ns_returns_retained attribute from the first declaration to later declarations. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141957 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 0b3f0c6e84..97a136f895 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1439,6 +1439,9 @@ def err_cconv_varargs : Error< def err_regparm_mismatch : Error<"function declared with with regparm(%0) " "attribute was previously declared " "%plural{0:without the regparm|:with the regparm(%1)}1 attribute">; +def err_returns_retained_mismatch : Error< + "function declared with the ns_returns_retained attribute " + "was previously declared without the ns_returns_retained attribute">; def err_objc_precise_lifetime_bad_type : Error< "objc_precise_lifetime only applies to retainable types; type here is %0">; def warn_objc_precise_lifetime_meaningless : Error< diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index ecc81ccb83..71b3c526a1 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1752,6 +1752,18 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) { RequiresAdjustment = true; } + // Merge ns_returns_retained attribute. + if (OldTypeInfo.getProducesResult() != NewTypeInfo.getProducesResult()) { + if (NewTypeInfo.getProducesResult()) { + Diag(New->getLocation(), diag::err_returns_retained_mismatch); + Diag(Old->getLocation(), diag::note_previous_declaration); + return true; + } + + NewTypeInfo = NewTypeInfo.withProducesResult(true); + RequiresAdjustment = true; + } + if (RequiresAdjustment) { NewType = Context.adjustFunctionType(NewType, NewTypeInfo); New->setType(QualType(NewType, 0)); diff --git a/test/SemaObjCXX/arc-overloading.mm b/test/SemaObjCXX/arc-overloading.mm index 1e0647ab70..dad5d0f705 100644 --- a/test/SemaObjCXX/arc-overloading.mm +++ b/test/SemaObjCXX/arc-overloading.mm @@ -192,3 +192,11 @@ void f9790531_2(char * inClientData); // expected-note {{candidate function not f9790531_2(self); // expected-error {{no matching function for call to 'f9790531_2'}} } @end + +class rdar10142572 { + id f() __attribute__((ns_returns_retained)); + id g(); // expected-note{{previous declaration}} +}; + +id rdar10142572::f() { return 0; } // okay: merged down +id __attribute__((ns_returns_retained)) rdar10142572::g() { return 0; } // expected-error{{function declared with the ns_returns_retained attribute was previously declared without the ns_returns_retained attribute}}