ThePhD / sol2

Sol3 (sol2 v3.0) - a C++ <-> Lua API wrapper with advanced features and top notch performance - is here, and it's great! Documentation:
http://sol2.rtfd.io/
MIT License
4.06k stars 493 forks source link

Unreachable code warning compiling under MSVC with LTO #1493

Open jcmoyer opened 1 year ago

jcmoyer commented 1 year ago

In my setup I'm compiling Lua as part of my project, and when I turn on LTO via CMAKE_INTERPROCEDURAL_OPTIMIZATION, the return listed below is considered unreachable by MSVC. I guess MSVC can analyze through multiple Lua calls and determine that luaL_error eventually calls a function marked noreturn. I'm compiling with /W4 /WX and this becomes an error during linking, so marking the library as SYSTEM in cmake doesn't suppress the error. Commenting out the return fixes the issue in MSVC, but I don't know if it'll break other compilers.

Tested with Sol 3.3.0, Lua 5.4.4, cl 19.36.32532 x64.

Sol config: SOL_USING_CXX_LUA, SOL_ALL_SAFETIES_ON, SOL_CHECK_ARGUMENTS

https://github.com/ThePhD/sol2/blob/eab1430ccdbf61a0d61d11bf86b4975838dcfb9a/include/sol/stack_core.hpp#L335-L343

I can try to provide a complete test case if necessary.