No warning on unused variable
Andrew Haley
aph@redhat.com
Tue Oct 24 17:08:00 GMT 2006
Dave Williss writes:
>
> > >
> > > Why did this not warn me about the unused stringstream?
> > [snip]
> > > it is concievable that declaring this object
> > > might be sufficient for some action to be taken by the code, thus
> > > rendering it incorrect for -Wall to report it.
> >
> > You got it in one. For example, you might see
> >
> > {
> > lock myLock;
> > ...
> > }
> >
> > where the lock constructor locks memory and the destructor releases
> > it.
> >
> It might be nice if g++ could add an __attribute__ setting so you could
> tag a class with something like ctor_has_no_useful_side_effects.
> Classes with this attribute could then be allowed to raise the "declared
> but not used" warning. It would be most useful on things like
> std::string, which you also wouldn't want just laying around.
It's an interesting idea, for sure. I can't immediately think of any
big downside, but I'm not sure if such a patch would be accepted.
Andrew.
More information about the Gcc-help
mailing list