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

add TOML_DISABLE_CONDITIONAL_NOEXCEPT_LAMBDA workaround MSVC error C2057 #247

Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ UTF-8 decoding is performed using a state machine based on Bjoern Hoehrmann's '[
- **[@levicki](https://github.com/levicki)** - Helped design some new features
- **[@moorereason](https://github.com/moorereason)** - Reported a whole bunch of bugs
- **[@mosra](https://github.com/mosra)** - Created the awesome [m.css] used to generate the API docs
- **[@N-Dekker](https://github.com/N-Dekker)** - Added a workaround for the legacy lambda processor of MSVC 2019/2022
- **[@ned14](https://github.com/ned14)** - Reported a bunch of bugs and helped design some new features
- **[@okureta](https://github.com/okureta)** - Reported a bug
- **[@prince-chrismc](https://github.com/prince-chrismc)** - Added toml++ to ConanCenter, and fixed some typos
Expand Down
3 changes: 3 additions & 0 deletions include/toml++/impl/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,10 @@ TOML_NAMESPACE_START
static_cast<node_ref>(static_cast<Array&&>(arr)[i])
.visit(
[&]([[maybe_unused]] auto&& elem) //
// Define this macro as a workaround to compile errors caused by a bug in MSVC's "legacy lambda processor".
#if !TOML_DISABLE_CONDITIONAL_NOEXCEPT_LAMBDA
noexcept(for_each_is_nothrow_one<Func&&, Array&&, decltype(elem)>::value)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For what it's worth, I did try to work around the problem (locally) by introducing a variable template for_each_is_nothrow_one_v, in order to do:

    noexcept( for_each_is_nothrow_one_v<Func&&, Array&&, decltype(elem)> )

But it still did not make the old legacy lambda processor happy. 🤷

#endif
{
using elem_ref = for_each_elem_ref<decltype(elem), Array&&>;
static_assert(std::is_reference_v<elem_ref>);
Expand Down
11 changes: 11 additions & 0 deletions include/toml++/impl/preprocessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,17 @@ TOML_ENABLE_WARNINGS;
/// \detail Defaults to `0`.
//# }}

#ifndef TOML_DISABLE_CONDITIONAL_NOEXCEPT_LAMBDA
#define TOML_DISABLE_CONDITIONAL_NOEXCEPT_LAMBDA 0
#endif
//# {{
/// \def TOML_DISABLE_CONDITIONAL_NOEXCEPT_LAMBDA
/// \brief Disable using noexcept(<condition>) in lambda definitions within the toml++ library implementation.
/// \detail This macro offers a workaround to a bug in the old "legacy lambda processor" of Visual C++, which
/// caused compile errors like "error C2057: expected constant expression", when it encountered such lambda's.
/// These compile errors were reported by Kevin Dick, Jan 19, 2024, at https://github.com/marzer/tomlplusplus/issues/219
//# }}

/// @}
//#====================================================================================================================
//# CHARCONV SUPPORT
Expand Down
3 changes: 3 additions & 0 deletions include/toml++/impl/table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,10 @@ TOML_NAMESPACE_START
static_cast<node_ref>(*kvp.second)
.visit(
[&]([[maybe_unused]] auto&& v) //
// Define this macro as a workaround to compile errors caused by a bug in MSVC's "legacy lambda processor".
#if !TOML_DISABLE_CONDITIONAL_NOEXCEPT_LAMBDA
noexcept(for_each_is_nothrow_one<Func&&, Table&&, decltype(v)>::value)
#endif
{
using value_ref = for_each_value_ref<decltype(v), Table&&>;
static_assert(std::is_reference_v<value_ref>);
Expand Down
10 changes: 10 additions & 0 deletions toml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,10 @@ TOML_ENABLE_WARNINGS;
#define TOML_ENABLE_FLOAT16 0
#endif

#ifndef TOML_DISABLE_CONDITIONAL_NOEXCEPT_LAMBDA
#define TOML_DISABLE_CONDITIONAL_NOEXCEPT_LAMBDA 0
#endif

#if !defined(TOML_FLOAT_CHARCONV) && (TOML_GCC || TOML_CLANG || (TOML_ICC && !TOML_ICC_CL))
// not supported by any version of GCC or Clang as of 26/11/2020
// not supported by any version of ICC on Linux as of 11/01/2021
Expand Down Expand Up @@ -6799,7 +6803,10 @@ TOML_NAMESPACE_START
static_cast<node_ref>(static_cast<Array&&>(arr)[i])
.visit(
[&]([[maybe_unused]] auto&& elem) //
// Define this macro as a workaround to compile errors caused by a bug in MSVC's "legacy lambda processor".
#if !TOML_DISABLE_CONDITIONAL_NOEXCEPT_LAMBDA
noexcept(for_each_is_nothrow_one<Func&&, Array&&, decltype(elem)>::value)
#endif
{
using elem_ref = for_each_elem_ref<decltype(elem), Array&&>;
static_assert(std::is_reference_v<elem_ref>);
Expand Down Expand Up @@ -8161,7 +8168,10 @@ TOML_NAMESPACE_START
static_cast<node_ref>(*kvp.second)
.visit(
[&]([[maybe_unused]] auto&& v) //
// Define this macro as a workaround to compile errors caused by a bug in MSVC's "legacy lambda processor".
#if !TOML_DISABLE_CONDITIONAL_NOEXCEPT_LAMBDA
noexcept(for_each_is_nothrow_one<Func&&, Table&&, decltype(v)>::value)
#endif
{
using value_ref = for_each_value_ref<decltype(v), Table&&>;
static_assert(std::is_reference_v<value_ref>);
Expand Down