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

Instruct msvc to report the true value in __cplusplus #2353

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -2656,21 +2656,28 @@ constexpr auto get_arg_index_by_name(basic_string_view<Char> name) -> int {
if constexpr (detail::is_statically_named_arg<T>()) {
if (name == T::name) return N;
}
if constexpr (sizeof...(Args) > 0)
if constexpr (sizeof...(Args) > 0) {
return get_arg_index_by_name<N + 1, Args...>(name);
(void)name; // Workaround an MSVC bug about "unused" parameter.
return invalid_arg_index;
} else {
(void)name; // Workaround an MSVC bug about "unused" parameter.
return invalid_arg_index;
}
}
#endif

template <typename... Args, typename Char>
FMT_CONSTEXPR auto get_arg_index_by_name(basic_string_view<Char> name) -> int {
#if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS
if constexpr (sizeof...(Args) > 0)
if constexpr (sizeof...(Args) > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there will be an unbalanced { if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS is defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. There are fully balanced if-else branches. Otherwise the code wouldn't compile on my system, like at all. I've checked with FMT_USE_NONTYPE_TEMPLATE_PARAMETERS overridden to both 0and 1, and with 1 being auto-detected.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, it does look correct.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not uncommon for EDG (the intellisense compiler) be out of sync with the actual compiler during the preview phase. As long as msvc reports correctly (and it does), we're fine.

return get_arg_index_by_name<0, Args...>(name);
#endif
} else {
(void)name;
return invalid_arg_index;
}
#else
(void)name;
return invalid_arg_index;
#endif
}

template <typename Char, typename ErrorHandler, typename... Args>
Expand Down
2 changes: 1 addition & 1 deletion include/fmt/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ struct ostream_params {

FMT_END_DETAIL_NAMESPACE

static constexpr detail::buffer_size buffer_size;
constexpr detail::buffer_size buffer_size;

/** A fast output stream which is not thread-safe. */
class FMT_API ostream final : private detail::buffer<char> {
Expand Down
6 changes: 4 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ if (FMT_CAN_MODULE)

add_fmt_test(module-test MODULE)
if (MSVC)
target_compile_options(test-module PRIVATE /utf-8)
target_compile_options(module-test PRIVATE /utf-8)
target_compile_options(test-module PRIVATE /utf-8 /Zc:__cplusplus
/Zc:externConstexpr /Zc:inline)
target_compile_options(module-test PRIVATE /utf-8 /Zc:__cplusplus
/Zc:externConstexpr /Zc:inline)
endif ()
endif ()

Expand Down