Page 1 of 1

Compiler Warning Only in Release

PostPosted: Mon Jun 01, 2020 1:35 am
by d7d1cd
Welcome all. Wrote the following test code:
Code: Select all
/*----- unit1.h -----*/
inline bool Foo();
 
 
/*----- unit1.cpp -----*/
bool TForm1::Foo()
{
  int b;
  int i;
 
  if (b == 7) i = 1;
  else if (b == 8) i = 2;
  else return true;
 
  return false;
}

Compilation of this code in Debug mode is successful. In Release mode, a warning appears that the function should return a value ([bcc32 Warning] Unit1.cpp (32): W8070 Function should return a value).
If you remove the inline keyword, the warning disappears. It also disappears if line 13 is replaced with this code:
Code: Select all
...
  else i = 3;
 
  if (i == 3) return true;
...

Can you explain why the warning appears? Moreover, it appears only in the "classic" compiler. In Clang, this is not observed.

Re: Compiler Warning Only in Release

PostPosted: Mon Jun 01, 2020 12:46 pm
by rlebeau
d7d1cd wrote:Welcome all. Wrote the following test code:


Why are you marking a class method as 'inline' when its implementation is in another file? The compiler won't be able to inline such code, so why even try?