8000
Skip to content

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

Merged
vitaut merged 3 commits intofmtlib:masterfrom
hmbj:fix-condition-is-constexpr-msvc-level4-warning
Jun 2, 2023
Merged

Fix MSVC warning in std::chrono::time_point formatter#3475
vitaut merged 3 commits intofmtlib:masterfrom
hmbj:fix-condition-is-constexpr-msvc-level4-warning

Conversation

@hmbj
Copy link
Copy Markdown
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
@vitaut vitaut merged commit 8abfc14 into fmtlib:master Jun 2, 2023
@vitaut
Copy link
Copy Markdown
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

0