Skip to content

Commit 8eb4012

Browse files
authored
TOML_DISABLE_NOEXCEPT_NOEXCEPT workaround MSVC bug noexcept + modules (#271)
1 parent 5abab00 commit 8eb4012

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

include/toml++/impl/preprocessor.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,22 @@ TOML_ENABLE_WARNINGS;
12521252
/// These compile errors were reported by Kevin Dick, Jan 19, 2024, at https://github.com/marzer/tomlplusplus/issues/219
12531253
//# }}
12541254

1255+
#ifndef TOML_DISABLE_NOEXCEPT_NOEXCEPT
1256+
#define TOML_DISABLE_NOEXCEPT_NOEXCEPT 0
1257+
#ifdef _MSC_VER
1258+
#if _MSC_VER <= 1943 // Up to Visual Studio 2022 Version 17.13.6
1259+
#undef TOML_DISABLE_NOEXCEPT_NOEXCEPT
1260+
#define TOML_DISABLE_NOEXCEPT_NOEXCEPT 1
1261+
#endif
1262+
#endif
1263+
#endif
1264+
//# {{
1265+
/// \def TOML_DISABLE_NOEXCEPT_NOEXCEPT
1266+
/// \brief Disable using noexcept(noexcept(<expression>)) within the toml++ library implementation.
1267+
/// \detail This macro offers a workaround to a bug in Visual C++ (Visual Studio 2022), which caused
1268+
/// compile errors, saying: "error C3878: syntax error: unexpected token ',' following 'simple-type-specifier'"
1269+
//# }}
1270+
12551271
/// @}
12561272
//#====================================================================================================================
12571273
//# CHARCONV SUPPORT

include/toml++/impl/value.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,11 @@ TOML_NAMESPACE_START
266266
(impl::value_variadic_ctor_allowed<value<ValueType>, impl::remove_cvref<Args>...>::value),
267267
typename... Args)
268268
TOML_NODISCARD_CTOR
269-
explicit value(Args&&... args) noexcept(noexcept(value_type(
270-
impl::native_value_maker<value_type, std::decay_t<Args>...>::make(static_cast<Args&&>(args)...))))
269+
explicit value(Args&&... args)
270+
#if !TOML_DISABLE_NOEXCEPT_NOEXCEPT
271+
noexcept(noexcept(value_type(
272+
impl::native_value_maker<value_type, std::decay_t<Args>...>::make(static_cast<Args&&>(args)...))))
273+
#endif
271274
: val_(impl::native_value_maker<value_type, std::decay_t<Args>...>::make(static_cast<Args&&>(args)...))
272275
{
273276
#if TOML_LIFETIME_HOOKS

toml.hpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,16 @@ TOML_ENABLE_WARNINGS;
11371137
#define TOML_DISABLE_CONDITIONAL_NOEXCEPT_LAMBDA 0
11381138
#endif
11391139

1140+
#ifndef TOML_DISABLE_NOEXCEPT_NOEXCEPT
1141+
#define TOML_DISABLE_NOEXCEPT_NOEXCEPT 0
1142+
#ifdef _MSC_VER
1143+
#if _MSC_VER <= 1943 // Up to Visual Studio 2022 Version 17.13.6
1144+
#undef TOML_DISABLE_NOEXCEPT_NOEXCEPT
1145+
#define TOML_DISABLE_NOEXCEPT_NOEXCEPT 1
1146+
#endif
1147+
#endif
1148+
#endif
1149+
11401150
#if !defined(TOML_FLOAT_CHARCONV) && (TOML_GCC || TOML_CLANG || (TOML_ICC && !TOML_ICC_CL))
11411151
// not supported by any version of GCC or Clang as of 26/11/2020
11421152
// not supported by any version of ICC on Linux as of 11/01/2021
@@ -5088,8 +5098,11 @@ TOML_NAMESPACE_START
50885098
(impl::value_variadic_ctor_allowed<value<ValueType>, impl::remove_cvref<Args>...>::value),
50895099
typename... Args)
50905100
TOML_NODISCARD_CTOR
5091-
explicit value(Args&&... args) noexcept(noexcept(value_type(
5092-
impl::native_value_maker<value_type, std::decay_t<Args>...>::make(static_cast<Args&&>(args)...))))
5101+
explicit value(Args&&... args)
5102+
#if !TOML_DISABLE_NOEXCEPT_NOEXCEPT
5103+
noexcept(noexcept(value_type(
5104+
impl::native_value_maker<value_type, std::decay_t<Args>...>::make(static_cast<Args&&>(args)...))))
5105+
#endif
50935106
: val_(impl::native_value_maker<value_type, std::decay_t<Args>...>::make(static_cast<Args&&>(args)...))
50945107
{
50955108
#if TOML_LIFETIME_HOOKS

0 commit comments

Comments
 (0)