Bugs you expected to throw a compiler error ...

Started by
23 comments, last by alvaro 12 years, 11 months ago
That should also pump out an unused variable warning, though it might require some compiler flag to do so. If you really want to make it a compile error, you could also enable warnings are errors.

Particularly if your compile times are fairly short, it's not a bad idea to turn on all warnings and enable warnings are errors.
Advertisement
Yes, if the compiler gives out a warning, you can't complain because you ignored it. We always compile with warnings as errors at work, and I never ignore warnings even on hobby projects.
I once had an error that I expected the compiler to flag. But didn't.

this was about 10 years ago, and I was programming a "toy OS" (called nachOS)
it was done in C (not C++) so everything was ok, but then random errors would occur, random values sometimes, and other times those values where correct....
it didn't make sense... it took me 3 days to find out the problem, going line by line, debugging every variable etc.


// we do something here
something = somethingelse;
more code and more code


see the error?
obviously // is a c++ thing, so the comments had to be /* we do something here */
I just changed that and the program started to work perfectly. So yeah, don't trust the compiler. just because it said "it's ok, there are no errors here" doesn't mean it's true!
There are several bugs that I was surprised to discover that the compiler doesn't warn about. For example, returning a reference to a local variable.
I trust exceptions about as far as I can throw them.
g++ does warn about that:
warning: reference to local variable ‘result’ returned[/quote]

This topic is closed to new replies.

Advertisement