Re: Incorrect block warnings
Re: Incorrect block warnings
- Subject: Re: Incorrect block warnings
- From: Steve Christensen <email@hidden>
- Date: Sat, 14 May 2011 14:27:57 -0700
I've run across this when doing block-based animation on iOS, but it should be the same issue for OS X. I believe someone mentioned awhile back that a local variable (or self) referenced inside the block is a separate variable provided to the block that contains the same value as the original, thus it looks to the compiler like the block's copy is shadowing the original one.
What I've done to get rid of that warning is to do the following.
#pragma GCC diagnostic ignored "-Wshadow" // turn off bogus shadowed variable warnings in GCD blocks
- (void) methodWithBlock
{
...
}
#pragma GCC diagnostic warning "-Wshadow" // restore warnings for shadowed variables
This also implies that if you do, in fact, have a real shadowed variable, you won't be warned. I haven't actually run into that case myself so this solution works for me.
On May 13, 2011, at 10:46 PM, Rick Mann wrote:
> Xcode 3.2.6, GCC 4.2, Cocoa App, OS X 10.6.7
>
> I have a simple bit of code in a .mm file:
>
> [snip]
>
> I get the following complaints from the compiler. However, the code seems to run just fine.
>
> /Users/me/LZRepo/Foo/trunk/xcode/../src/Cocoa/Foo/FooDocument.mm:231: warning: declaration of 'sp' shadows a previous local
> /Users/me/LZRepo/Foo/trunk/xcode/../src/Cocoa/Foo/FooDocument.mm:210: warning: shadowed declaration is here
> /Users/me/LZRepo/Foo/trunk/xcode/../src/Cocoa/Foo/FooDocument.mm:235: warning: declaration of 'FooDocument* const self' shadows a parameter
> /Users/me/LZRepo/Foo/trunk/xcode/../src/Cocoa/Foo/FooDocument.mm:208: warning: shadowed declaration is here
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden