lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello!

Visual Studio 2008 Professional with Win32 and ARMV4I compilers here

Using Warning Level 4:
----------------------

return (exit(status), 0);

-> warning C4702: unreachable code

if (L) exit(status);
return 0;

-> no warning


exit(status);
return 0;

-> warning C4702: unreachable code


Using Warning Level 3:
----------------------

return (exit(status), 0);

-> no warning

if (L) exit(status);
return 0;

-> no warning


exit(status);
return 0;

-> no warning

- - -
exit() is annotated as "noreturning" in Microsofts stdlib headers, so the compiler expects not to return
after exit().
- - -

When compiling the complete lua5.2 DLL with warning level 4, I get several reasonable "possible loss of data"
warnings which could be avoided by proper explicit casting.

Then I get some "unreachable" code warnings in places where luaG_runerror() is followed by "return 0;". This is understandable, since luaG_runerror() is annotated as "noreturning" via "l_noret".

To be consistent, either don't use l_noret in Lua code, use "return 0" after not-returning function calls and use compiler warning settings to filter the "unreachable code" warning messages with "smart" compilers -- or use l_noret wherever applicable, remove the "return 0" after not-returning function calls and use compiler warning settings to filter the "function must return a value" warning messages with the "dumb" compilers.

Another idea: Is it feasible to redeclare exit() this way:

  extern l_noret exit(int code);

inside some appropriate Lua header to help "not so dumb" compilers which have stdlib.h headers without annotation?

Best Regards,

    Jorge-León


On 11/29/11 13:19, Roberto Ierusalimschy wrote:
   return (exit(status), 0);
   if (L) exit(status);  /* test to avoid warnings of 'exit' x 'return' */
   return 0;
I have tested the previous two patches on the bunch of compilers
currently installed on my computer.
None of them produced a warning for both tricks.
The first one is probably better because it avoids an additional
useless test-and-jump.
According to [1], something similar to the first option gave warnings
in MSVC2005.

[1] http://lua-users.org/lists/lua-l/2008-01/msg00375.html

It would be nice if other people could try these options in their
systems.

-- Roberto