Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VisualStudio 15.7.x compilation error in /W4 /WX #748

Closed
christophe-calmejane opened this issue May 22, 2018 · 15 comments
Closed

VisualStudio 15.7.x compilation error in /W4 /WX #748

christophe-calmejane opened this issue May 22, 2018 · 15 comments

Comments

@christophe-calmejane
Copy link

Using just released v5.0, I've got some compilation errors using VS15.7.x compiler when /W4 and /WX flags are set: "Unreachable code"

I've a workaround that consists of disabling this warning before including fmt, but it's not very "clean". Maybe there is a way to fix this warning (or to add the pragma push/disable/pop) directly in fmt headers.

This simple code (compiled in release) cause a compilation error with /W4 /WX:
#include <fmt/format.h> int main(int, char**) { fmt::format("Test"); return 0; }

The current fix for this is (win32 only)
#pragma warning(push) #pragma warning(disable:4702) #include <fmt/format.h> #pragma warning(pop)

Haven't tested on clang/gcc yet.

@eliaskosunen
Copy link
Contributor

Plenty of warnings are fixed on #736

@vitaut
Copy link
Contributor

vitaut commented May 23, 2018

Could you post the full warning message? I don't have access to a Windows machine and the warning doesn't reproduce on godbolt: https://godbolt.org/g/c67EiY

@christophe-calmejane
Copy link
Author

1>test.cpp
1>c:\dev\test\fmtlib\include\fmt\format.h(1672): error C2220: warning treated as error - no 'object' file generated
1>c:\dev\test\fmtlib\include\fmt\format.h(1672): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\format.h(1672): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\format.h(1672): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\format.h(1672): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\format.h(1672): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\format.h(1672): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\format.h(1672): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\format.h(1672): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\format.h(1672): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\format.h(1648): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\format.h(1648): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\format.h(1648): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\format.h(1648): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\format.h(1648): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\format.h(1648): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\format.h(1648): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\format.h(1648): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\format.h(1648): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\core.h(744): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\format.h(1267): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\format.h(2004): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\format.h(2048): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\format.h(2062): warning C4702: unreachable code
1>c:\dev\test\fmtlib\include\fmt\format.h(2066): warning C4702: unreachable code
1>Done building project "Test.vcxproj" -- FAILED.

This is using commitID 5386f1d (release branch)

@mwinterb
Copy link
Contributor

mwinterb commented May 23, 2018 via email

@christophe-calmejane
Copy link
Author

Optimizer is not disabled, it happens only in a Release build. Debug build is fine.
I'm just using a cmake file as simple as this to create the project, run cmake and compile:

cmake_minimum_required(VERSION 3.5)
project(test LANGUAGES C CXX VERSION 1.0.0.0)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
add_subdirectory(fmtlib)
add_executable(Test test.cpp)
target_link_libraries(Test PRIVATE fmt-header-only)

@mwinterb
Copy link
Contributor

mwinterb commented May 23, 2018 via email

@christophe-calmejane
Copy link
Author

Yeah sorry I should have pasted the cmake source before :)
Like I said, right now I've to disable the warnings (win32 only) before including fmt, so if it can be done directly in the header it would be better for everyone.
Ty (and gn)

@Remotion
Copy link
Contributor

Remotion commented May 23, 2018

Can we simple use such code to disable unreachable code warning ?

#if _MSC_VER && !defined(__clang__) && !defined(__INTEL_COMPILER)
#pragma warning( push )
#pragma warning( disable: 4702 ) // unreachable code
#endif
#if _MSC_VER && !defined(__clang__) && !defined(__INTEL_COMPILER)
#pragma warning( pop )
#endif // warning 4702 is back

@christophe-calmejane
Copy link
Author

It's what I'm doing before including fmt (except I don't care about excluding vs_clang or intel, but the idea is here).

@vitaut
Copy link
Contributor

vitaut commented May 26, 2018

@christophe-calmejane what's the complete list of command-line options passed to cl (in addition to /W4 /WX)? Maybe I could repro it on godbolt after all.

@christophe-calmejane
Copy link
Author

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.14.26428\bin\HostX86\x86\CL.exe /c /IC:\test\fmtlib\include /nologo /W4 /WX /diagnostics:classic /O2 /Ob2 /Oy- /D WIN32 /D _WINDOWS /D NDEBUG /D FMT_HEADER_ONLY=1 /D "CMAKE_INTDIR="Release"" /D _MBCS /Gm- /EHsc /MD /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /std:c++17 /Fo"Test.dir\Release\" /Fd"Test.dir\Release\vc141.pdb" /Gd /TP /analyze- /FC /errorReport:queue C:\test\test.cpp

@vitaut
Copy link
Contributor

vitaut commented Jun 3, 2018

Should be fixed in f8d5220, thanks for reporting.

@vitaut
Copy link
Contributor

vitaut commented Jun 3, 2018

Had to temporarily revert part of the fix because of some MSVC issue, but will bring it back.

@vitaut
Copy link
Contributor

vitaut commented Jun 4, 2018

On further inspection, it turned out that the above commit doesn't solve the issue, reopening.

@vitaut vitaut reopened this Jun 4, 2018
@vitaut
Copy link
Contributor

vitaut commented Jun 4, 2018

Here goes a proper fix: 252f11f

@vitaut vitaut closed this as completed Jun 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants