0

Why does this function compile under release build...

unsigned int blah()
{

}

but not under debug build? It gives an error that says: 'blah': must return a value. What I want to know is the technical reason that this occurs. Why will it accept one but not the other? If it matters, I am using VS2015.

  • I'm not sure if the standard mandates it needs to issue a diagnostic here or not. I can tell you it is undefined behavior. – NathanOliver Sep 16 '16 at 18:26
  • It shouldn't compile in either. If it compiles in release, it is probably because the function is being optimized away if you aren't trying to call it. – Cory Kramer Sep 16 '16 at 18:27
  • Check your release build settings the errors and warning section. I bet they are different from the debug build. – Richard Critten Sep 16 '16 at 18:30
  • @CoryKramer - if the function is called, the behavior is undefined. That does not mean that the code shouldn't compile. The C++ language definition only requires a diagnostic here. – Pete Becker Sep 16 '16 at 18:32
  • @PeteBecker Correct, but the OP mentioned they were using VS, I just know that happens to be a full-blown compiler error in VS. – Cory Kramer Sep 16 '16 at 18:34
  • @CoryKramer - then you need to say that. Especially since the code is valid as long as this function isn't called. – Pete Becker Sep 16 '16 at 18:37

0 Answers0