This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
No warning about accidental cast(?)
- From: Arend-Jan Wijtzes <ajwytzes at wise-guys dot nl>
- To: gcc-help at gcc dot gnu dot org
- Date: Tue, 12 Jun 2007 11:46:53 +0200
- Subject: No warning about accidental cast(?)
For the following statement:
int main()
{
int(1);
}
the compiler rightfully issues a warning "warning: statement has no effect"
However in this case:
struct X
{
X(int _a) : a(_a) { }
int a;
};
int main()
{
X(1); // author intended to write X x(1);
}
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?
Regards,
Arend-Jan
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.