Re: Another useless warning - 'Hidden Local Variables'
Re: Another useless warning - 'Hidden Local Variables'
- Subject: Re: Another useless warning - 'Hidden Local Variables'
- From: "Eric Miller" <email@hidden>
- Date: Wed, 23 Jul 2008 09:26:24 -0400
There's nothing useless about it. It is reporting exactly what it is
suppose to. There really isn't an easy way to determine which warnings
are harmless. For example, would want to catch this?
class Foo {
...
void doSomething(int key);
int id;
};
int lookupIdInDatabase(int key);
void Foo::doSomething(int id) // Shadow warning here
{
id = lookupIdInDatabase(id);
}
Is this harmless or not? The original author could be using id as a
local variable to hold the result and not want it saved in the object.
Shadowing does not cause ambiguity for the compiler, it just uses the
most local definition. Syntactically the code is correct, it's just
suspicious. Many languages make shadowing an error for this reason.
Having gone through cleanups in the past, you have my sympathy.
Regards,
Eric
On Wed, Jul 23, 2008 at 8:23 AM, Matt Gough <email@hidden> wrote:
> I was hoping to use 'Hidden local variables' (GCC_WARN_SHADOW) to catch this
> sort of common error:
>
> {
> bool eraseEntireInternet = true;
> if (!AskUserIfTheyReallyWantToEraseEntireInternet())
> {
> bool eraseEntireInternet = false;
> // Oops - I meant to assign to the top level value here
> // but I stupidly copied the entire declaration
> // and just changed true to false.
> ....
> }
>
> if (eraseEntireInternet)
> EraseEntireInternet(); // Oh well - What was it ever good for
> anyway :)
> }
>
>
> but it is really useless as it also warns about this sort of thing:
>
> class Foo
> {
> size_t size() const;
> void setSize(size_t size);
>
> size_t mSize;
> }
>
> void Foo::setSize(size_t size) << Warning - declaration of 'size' shadows a
> member of 'this'
> {
> mSize = size;
> }
>
> To me this is just dumb that Foo::size() is considered a contender for being
> shadowed. I know that it could be interpreted as me wanting to assign the
> address of Foo::size() to mSize.
>
> Is there anyway to make this warning only consider real variables (either
> local, global or class) and to not moan about method names too? Our project
> has over 10,000 such warnings, so I am not going to go through it and rename
> all my method parameters to avoid such clashes. As such, its possible that a
> few 'real' problems will be missed.
>
>
> Matt Gough
> _______________________________________________
> 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
>
_______________________________________________
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