Workaround Clang <3.6 apply_r() runtime failure

Lambdas with certain noexcept specifiers are deemed non-invocable at
compile-time, failing at runtime.
This commit is contained in:
Florian Albrechtskirchinger 2022-05-03 20:09:44 +02:00
parent 6e1056dd53
commit f8ddc20d5c
No known key found for this signature in database
GPG Key ID: 19618CE9B2D4BE6D
3 changed files with 22 additions and 8 deletions

View File

@ -5397,7 +5397,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
R apply_r(Fn&& f, Args&& ... args)
{
R out;
apply_cb([&out](R && r) noexcept(noexcept(out = std::forward<decltype(r)>(r)))
// dynamic noexcept specifier fails to compile on Clang <3.6
apply_cb([&out](R && r)
#if !defined(__clang__) || (defined(__clang__) && __clang_major__ == 3 && __clang_minor__ > 5)
noexcept(noexcept(out = std::forward<decltype(r)>(r)))
#endif
{
out = std::forward<decltype(r)>(r);
}, std::forward<Fn>(f), std::forward<Args>(args)...);
@ -5408,7 +5412,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
R apply_r(Fn&& f, Args&& ... args) const
{
R out;
apply_cb([&out](R && r) noexcept(noexcept(out = std::forward<decltype(r)>(r)))
// dynamic noexcept specifier fails to compile on Clang <3.6
apply_cb([&out](R && r)
#if !defined(__clang__) || (defined(__clang__) && __clang_major__ == 3 && __clang_minor__ > 5)
noexcept(noexcept(out = std::forward<decltype(r)>(r)))
#endif
{
out = std::forward<decltype(r)>(r);
}, std::forward<Fn>(f), std::forward<Args>(args)...);

View File

@ -23777,7 +23777,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
R apply_r(Fn&& f, Args&& ... args)
{
R out;
apply_cb([&out](R && r) noexcept(noexcept(out = std::forward<decltype(r)>(r)))
// dynamic noexcept specifier fails to compile on Clang <3.6
apply_cb([&out](R && r)
#if !defined(__clang__) || (defined(__clang__) && __clang_major__ == 3 && __clang_minor__ > 5)
noexcept(noexcept(out = std::forward<decltype(r)>(r)))
#endif
{
out = std::forward<decltype(r)>(r);
}, std::forward<Fn>(f), std::forward<Args>(args)...);
@ -23788,7 +23792,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
R apply_r(Fn&& f, Args&& ... args) const
{
R out;
apply_cb([&out](R && r) noexcept(noexcept(out = std::forward<decltype(r)>(r)))
// dynamic noexcept specifier fails to compile on Clang <3.6
apply_cb([&out](R && r)
#if !defined(__clang__) || (defined(__clang__) && __clang_major__ == 3 && __clang_minor__ > 5)
noexcept(noexcept(out = std::forward<decltype(r)>(r)))
#endif
{
out = std::forward<decltype(r)>(r);
}, std::forward<Fn>(f), std::forward<Args>(args)...);

View File

@ -336,10 +336,6 @@ TEST_CASE("apply*() functions")
}
}
// apply_cb() (which apply_r() is based on) fails on Clang
// due to is_invocable not yielding true as expected
// while testing the invocable implementation Clang 3.5 crashed
#if !defined(__clang__) || (defined(__clang__) && __clang_major__ == 3 && __clang_minor__ < 6)
SECTION("apply_r()")
{
SECTION("value types")
@ -653,6 +649,8 @@ TEST_CASE("apply*() functions")
CHECK(f.bar == 42);
}
}
// add functor
}
}