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

MSVC warning - C4127: conditional expression is constant #4220

Closed
remyjette opened this issue Oct 29, 2024 · 3 comments
Closed

MSVC warning - C4127: conditional expression is constant #4220

remyjette opened this issue Oct 29, 2024 · 3 comments

Comments

@remyjette
Copy link

Seeing this on latest master.

minimal repro:

CMakeLists.txt

cmake_minimum_required(VERSION 3.20)
project(example)

add_executable(example main.cpp)

add_subdirectory(fmt)
target_link_libraries(example PRIVATE fmt)

target_compile_options(example PRIVATE "/WX" "/W4")

main.cpp

#include <fmt/format.h>

int main() {
    fmt::print("foo");
}
D:\src\example>cmake -S. -Bbuild -G"Visual Studio 17 2022"
-- The C compiler identification is MSVC 19.41.34123.0
-- The CXX compiler identification is MSVC 19.41.34123.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.41.34120/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.41.34120/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- {fmt} version: 11.0.2
-- Build type:
-- Configuring done (3.6s)
-- Generating done (0.1s)
-- Build files have been written to: D:/src/example/build

D:\src\example>cmake --build build
MSBuild version 17.11.9+a69bbaaf5 for .NET Framework

  1>Checking Build System
  Building Custom Rule D:/src/example/fmt/CMakeLists.txt
  format.cc
  os.cc
  Generating Code...
  fmt.vcxproj -> D:\src\example\build\fmt\Debug\fmtd.lib
  Building Custom Rule D:/src/example/CMakeLists.txt
  main.cpp
D:\src\example\fmt\include\fmt\format.h(1793,25): error C2220: the following warning is treated as an error [D:\src\example\build\example.vcxproj]
  (compiling source file '../main.cpp')

D:\src\example\fmt\include\fmt\format.h(1793,25): warning C4127: conditional expression is constant [D:\src\example\build\example.vcxproj]
  (compiling source file '../main.cpp')

D:\src\example\fmt\include\fmt\format.h(1816,7): warning C4127: conditional expression is constant [D:\src\example\build\example.vcxproj]
  (compiling source file '../main.cpp')

D:\src\example\fmt\include\fmt\base.h(2888,7): warning C4127: conditional expression is constant [D:\src\example\build\example.vcxproj]
  (compiling source file '../main.cpp')
      D:\src\example\fmt\include\fmt\base.h(2888,7):
      the template instantiation context (the oldest one first) is
          D:\src\example\main.cpp(4,10):
          see reference to function template instantiation 'void fmt::v11::print<>(fmt::v11::fstring<>)' being compiled

If this was coming while compiling format.cc then I wouldn't mind doing a target_compile_options(fmt ...) to disable the warning on fmt, but since this is happening in a header I get it in my own target too. I'd rather not have to disable this warning on my whole project or wrap every #include <fmt/format.h> with pragmas to disable it.

@vitaut vitaut changed the title MSVC build failure - C4127: conditional expression is constant MSVC warning - C4127: conditional expression is constant Oct 29, 2024
@vitaut
Copy link
Contributor

vitaut commented Oct 31, 2024

This is a very low quality warning from MSVC but it can be suppressed by wrapping a condition in const_check. A PR would be welcome.

@UnrealKaraulov
Copy link

@vitaut closed as completed? really?

@phprus
Copy link
Contributor

phprus commented Nov 10, 2024

@UnrealKaraulov
Please, check the current master.

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

4 participants