Jump to content

  • Log In with Google      Sign In   
  • Create Account


Bugs you expected to throw a compiler error ...


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
24 replies to this topic

#21 Slavik81   Members   -  Reputation: 360

Like
0Likes
Like

Posted 25 May 2011 - 02:24 PM

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.

Sponsor:

#22 Álvaro   Crossbones+   -  Reputation: 12455

Like
0Likes
Like

Posted 25 May 2011 - 03:15 PM

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.

#23 stromchin   Members   -  Reputation: 102

Like
0Likes
Like

Posted 25 May 2011 - 11:00 PM

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!

#24 Storyyeller   Members   -  Reputation: 212

Like
0Likes
Like

Posted 26 May 2011 - 12:01 AM

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.

#25 Álvaro   Crossbones+   -  Reputation: 12455

Like
0Likes
Like

Posted 26 May 2011 - 06:55 AM

g++ does warn about that:

warning: reference to local variable ‘result’ returned






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS