No warning about accidental cast(?)

me22 me22.ca@gmail.com
Tue Jun 12 14:13:00 GMT 2007


On 12/06/07, Arend-Jan Wijtzes <ajwytzes@wise-guys.nl> wrote:
> However in this case:
>
> [...]
>
> No warning is issued. I tried this with gcc-3.3.6 and gcc-4.1.0.
> Is there any way to make the compiler warn about this mistake?
>
> P.S. If you're wondering what's the point if you're not going to use x,
> I use wrapper classes and the stack unwinding mechanism to auto-release
> locks or cleanup other resources.
>
I think you've probably found your own answer.  Constructors and
destructors can have arbitrary side effects, so GCC might just not
try.  The inliner might be able to reduce it to something that it
could figure out, but by then the variable information might be lost
(I don't know enough about internals to know).

And if you're using RAII classes for things like scoped locks, they
certainly have side effects, so the statement does have an effect.
For anything without side effects, you'll need to use it at some
point, where you'll get an undeclared identifier warning.

~ Scott

P.S. I think that's construction of a temporary, not a cast, technically.



More information about the Gcc-help mailing list