• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Compile error using @synchronized on methods that return values
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Compile error using @synchronized on methods that return values


  • Subject: Re: Compile error using @synchronized on methods that return values
  • From: Clark Cox <email@hidden>
  • Date: Sun, 8 Nov 2009 14:01:22 -0800

On Sun, Nov 8, 2009 at 12:11 PM, Stuart Malin <email@hidden> wrote:
> On Nov 8, 2009, at 2:56 PM, Adam R. Maxwel wrote:
>
>> On Nov 8, 2009, at 3:03 AM, Ken Tozier wrote:
>>
>>> "Control reaches end of non-void function"
>>>
>>> I Googled for "Objective-C accessors and @synchrinized" which seemed to
>>> indicate that the following was the correct way to handle it
>>>
>>> - (id) someMethod
>>> {
>>>        @synchronized(self)
>>>        {
>>>                return [somevalue autoreleae];
>>>        }
>>> }
>>>
>>> But I get the above error whenever I try to do it that way. Here's one of
>>> the actual methods with and without the @synchronized directive
>>
>> http://lists.apple.com/archives/Xcode-users/2009/Aug/msg00230.html
>>
>> More info can be found using google:
>>
>>
>> http://www.google.com/search?hl=en&q=site:lists.apple.com+@synchronized+Control+reaches+end+of+non-void+function&aq=f&oq=&aqi=
>
> Whether this warning is a bug (as suggested by the 00230 post referenced
> above) or not, I don't know (I'm way at the extreme end of my programmer's
> union card on this one).

The warning is a bug, and can be safely ignored. The compiler isn't
able to do the proper flow analysis to see that all ways out of the
function return a valid value. If you don't like ignoring warnings,
you can adjust your code to work around it:

- (id) someMethod
{
    id result = nil;
    @synchronized(self)
    {
        result = [somevalue autoreleae];
    }
    return result;
}

> But I suspect that from the posters comments in the
> post I reference below, it isn't a bug. The problem is, you can't return up
> the calling chain while being synchronized. Do whatever work it is that
> needs to be performed in a synchronized way, then return whatever result
> needs to be returned.

That is not true. @synchronized (as well as @try/@catch/@finally)
behave properly in the presence of returns. The problem here is in the
compiler's diagnostics, not in the code generated

--
Clark S. Cox III
email@hidden
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: Compile error using @synchronized on methods that return values (From: Stuart Malin <email@hidden>)

  • Prev by Date: Re: Best implementation for iTunes-like playlist structure?
  • Next by Date: Re: Best implementation for iTunes-like playlist structure?
  • Previous by thread: Re: Compile error using @synchronized on methods that return values
  • Next by thread: Re: Compile error using @synchronized on methods that return values
  • Index(es):
    • Date
    • Thread