-
-
Notifications
You must be signed in to change notification settings - Fork 163
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
base: master
Are you sure you want to change the base?
add TOML_DISABLE_CONDITIONAL_NOEXCEPT_LAMBDA workaround MSVC error C2057 #247
Conversation
include/toml++/impl/array.hpp
Outdated
// Define this macro as a workaround to MSVC 2019/2022 "error C2057: expected constant expression", | ||
// as reported by Kevin Dick, Jan 19, 2024, at https://github.com/marzer/tomlplusplus/issues/219 | ||
// These compile errors were caused by a bug in the old "legacy lambda processor" of Visual C++. | ||
#ifndef TOML_DISABLE_CONDITIONAL_NOEXCEPT_LAMBDA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, if you have a look in the "user defines" section of preprocessor.hpp you'll see that all the "bool-like" #define
compiler switches are implemented in terms of them being zero or non-zero, not simply defined or undefined.
This is based on a personal preference of mine; I don't like #define-based feature tests because they allow this logical inconsistency:
#define FOO_ENABLE_MAGIC_FEATURE 0
The user has defined it, but it's zero; if the feature test is implemented in terms of simply #define, this turns MAGIC_FEATURE on 😅
For for this new switch to fit in with the rest of them, you'd need to:
- have this in the user defines section of preprocessor.hpp:
#ifndef TOML_DISABLE_CONDITIONAL_NOEXCEPT_LAMBDA
#define TOML_DISABLE_CONDITIONAL_NOEXCEPT_LAMBDA 0
#endif
- change the logical tests to be simply
#if !TOML_DISABLE_CONDITIONAL_NOEXCEPT_LAMBDA
Oh, hmmn, also it seems like my CI setup in this repo has gotten stale 😅 Guess I should address whatever it's complaining about. |
Oh, actually, here's something else useful: MSVC actually gives you a way to detect that you're using the old or new preprocessor, per https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-170: It may be sensible to apply this detection to use it to set the default value of your new #ifndef TOML_DISABLE_CONDITIONAL_NOEXCEPT_LAMBDA
#if TOML_MSVC && (!defined(_MSVC_TRADITIONAL) || _MSVC_TRADITIONAL)
#define TOML_DISABLE_CONDITIONAL_NOEXCEPT_LAMBDA 1
#else
#define TOML_DISABLE_CONDITIONAL_NOEXCEPT_LAMBDA 0
#endif
#endif |
d595082
to
7d5918a
Compare
Offered a workaround to compile errors like "error C2057: expected constant expression", when using the "legacy lambda processor" of Visual C++. Such compile errors were reported by Kevin Dick, Jan 19, 2024, at issue marzer#219
7d5918a
to
9760658
Compare
Interesting, but does that also detect which lambda processor is being used? (The compile errors are caused by the lambda processor, not the preprocessor.) Update: With my local MSVC 2022 build of toml++.sln, @marzer Are you able to reproduce the original problem? (The compile errors when using the legacy lambda processor.) |
Oh, yeah, never mind. I was mixing up pre-processor with lambda processor. D'oh. Doesn't look like they have any magic macro for indicating the lambda processor that's in use. |
@@ -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) |
There was a problem hiding this comment.
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. 🤷
FYI, The legacy lambda processor errors are still there "by default", when generating a vcxproj file for a C++17 build by the latest version of CMake (version 3.31.5) and using the latest VS2022 update (version 17.12.4). Specifically, CMake generates project files that have Conformance mode = Default, which implies using the legacy lambda processor. |
Offered a workaround to compile errors like "error C2057: expected constant expression", when using the "legacy lambda processor" of Visual C++. Such compile errors were reported by Kevin Dick, Jan 19, 2024, at issue #219
origin/master
(if necessary)