]> granicus.if.org Git - clang/commitdiff
Under ARC, merge the bit corresponding to the ns_returns_retained
authorDouglas Gregor <dgregor@apple.com>
Fri, 14 Oct 2011 15:55:40 +0000 (15:55 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 14 Oct 2011 15:55:40 +0000 (15:55 +0000)
attribute from the first declaration to later declarations. Fixes
<rdar://problem/10142572>.

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/SemaObjCXX/arc-overloading.mm

index 0b3f0c6e84725cd8a3488d7fceb190fedfabfc15..97a136f89559a358eafc314efe989d3024cd3218 100644 (file)
@@ -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<
index ecc81ccb8397bbadfb1ab6ec3243ed7b3db2fbd0..71b3c526a167b0da276f1c31b232a41a4a8e3a4c 100644 (file)
@@ -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));
index 1e0647ab70377fb849751f2be75ae2ba3ef2493b..dad5d0f7051fdaba5f0e5e7b4cdf89016b5e78f0 100644 (file)
@@ -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}}