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

Fix MSVC warning in std::chrono::time_point formatter #3475

Merged

Conversation

hmbj
Copy link
Contributor

@hmbj hmbj commented Jun 2, 2023

The condition is constexpr causing MSVC level 4 warning:
warning C4127: conditional expression is constant

Made condition constexpr to eliminate the warning.

Code to reproduce the issue:

#include <fmt/chrono.h>
#include <fmt/xchar.h>
int main()
{
    fmt::format(L"{}", std::chrono::system_clock::time_point());
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.14)
project(mytest LANGUAGES CXX)

include(FetchContent)
FetchContent_Declare(fmt
  GIT_REPOSITORY  https://github.com/fmtlib/fmt.git
  GIT_TAG         10.0.0
)
FetchContent_MakeAvailable(fmt)

add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/W4>")
add_executable(mytest main.cpp)
target_compile_features(mytest PRIVATE cxx_std_17)
target_link_libraries(mytest PRIVATE fmt::fmt-header-only)

Hans-Martin B. Jensen added 2 commits June 2, 2023 14:32
The condition is constexpr causing MSVC level 4 warning:
warning C4127: conditional expression is constant

Changed the code to eliminate the warning
@hmbj hmbj changed the title Fix condition is constexpr msvc level4 warning Fix MSVC warning in std::chrono::time_point formatter Jun 2, 2023
@hmbj hmbj marked this pull request as ready for review June 2, 2023 13:46
include/fmt/chrono.h Outdated Show resolved Hide resolved
@vitaut vitaut merged commit 8abfc14 into fmtlib:master Jun 2, 2023
@vitaut
Copy link
Contributor

vitaut commented Jun 2, 2023

Thanks

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

Successfully merging this pull request may close these issues.

2 participants