Compiler Warning Only in Release

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

Compiler Warning Only in Release

Postby d7d1cd » Mon Jun 01, 2020 1:35 am

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.
d7d1cd
Active Poster
Active Poster
 
Posts: 10
Joined: Tue Dec 17, 2019 12:41 am

Re: Compiler Warning Only in Release

Postby rlebeau » Mon Jun 01, 2020 12:46 pm

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?
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1685
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA


Return to Technical

Who is online

Users browsing this forum: Google [Bot] and 33 guests