ut icon indicating copy to clipboard operation
ut copied to clipboard

Unreachable code shows in MSVC 16.9.5 in release mode.

Open Sebanisu opened this issue 4 years ago • 1 comments

Expected Behavior

Compile like it does in debug mode.

Actual Behavior

Had error with /WX on.

Steps to Reproduce the Problem

  1. I switched to release mode.
  2. Compile all
  3. This error error came up

Specifications

  • Version: trunk
  • Platform: MSVC 16.9.5
  • Subsystem: ?
====================[ Build | VIIIArchive_FileData | Release-Visual Studio ]====
"C:\Program Files\JetBrains\CLion 2020.2\bin\cmake\win\bin\cmake.exe" --build D:\dev\OpenVIII_CPP_WIP\cmake-build-release-visual-studio --target VIIIArchive_FileData
[ 50%] Built target VIIIArchive_External_lz4
[ 75%] Building CXX object tests/CMakeFiles/VIIIArchive_FileData.dir/FileData.cpp.obj
FileData.cpp
D:\dev\OpenVIII_CPP_WIP\cmake-build-release-visual-studio\_deps\ut-src\include\boost\ut.hpp(871) : error C2220: the following warning is treated as an error
D:\dev\OpenVIII_CPP_WIP\cmake-build-release-visual-studio\_deps\ut-src\include\boost\ut.hpp(871) : warning C4702: unreachable code
D:\dev\OpenVIII_CPP_WIP\cmake-build-release-visual-studio\_deps\ut-src\include\boost\ut.hpp(871) : warning C4702: unreachable code
NMAKE : fatal error U1077: 'C:\PROGRA~2\MICROS~1\2019\COMMUN~1\VC\Tools\MSVC\1428~1.299\bin\Hostx86\x86\cl.exe' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX86\x86\nmake.exe"' : return code '0x2'
Stop.

image So it's unhappy with a return false after the return true. I'm not sure how to make it happy. Though this might be a non issue as who is compiling tests in release mode?

Sebanisu avatar May 18 '21 13:05 Sebanisu

What we could do maybe is store the return value in a bool variable set to false. And instead of returning true. We set the value to true in the catch block. and return the variable for all cases.

template <class TExpr>
struct throws_<TExpr, void> : op {
  constexpr explicit throws_(const TExpr& expr)
      : value_{[&expr] {
          try {
            expr();
          } catch (...) {
            return true;
          }
          return false;
        }()} {}

becomes:

template <class TExpr>
struct throws_<TExpr, void> : op {
  constexpr explicit throws_(const TExpr& expr)
      : value_{[&expr] {
          bool retval = false;
          try {
            expr();
          } catch (...) {
            retval = true;
          }
          return retval;
        }()} {}

Sebanisu avatar May 18 '21 13:05 Sebanisu