This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: No warning about accidental cast(?)
- From: me22 <me22 dot ca at gmail dot com>
- To: "Arend-Jan Wijtzes" <ajwytzes at wise-guys dot nl>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 12 Jun 2007 09:27:34 -0400
- Subject: Re: No warning about accidental cast(?)
- References: <20070612094653.GE28238@vito.wise-guys.nl>
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.