Skip to content

Commit 04ff59c

Browse files
expected: force polyfill on all platforms to fix Linux-only -fno-exceptions build
Linux CI (clang + libstdc++-13) fails while macOS (libc++) and Windows (MSVC STL) pass because only libstdc++ gates __cpp_lib_expected under C++20, pulling in the real <expected> and its std::unexpected, which collides with libstdc++'s legacy void std::unexpected(). Use the exception-free kyty:: polyfill unconditionally on every platform. All call sites already use kyty::expected / kyty::unexpected, so no caller changes are needed. include/ and src/ copies remain byte-identical.
1 parent 3b10cba commit 04ff59c

2 files changed

Lines changed: 14 additions & 46 deletions

File tree

include/kyty_expected.hpp

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,19 @@
66
// Deliberately NOT defined in namespace std:
77
// * defining names in namespace std is undefined behavior,
88
// * libstdc++ >= 13 declares a legacy function `void std::unexpected()`
9-
// which would collide with a class template of the same name.
10-
// `kyty::expected` / `kyty::unexpected` are provided via using-declarations.
9+
// which collides with the real std::unexpected<T> from <expected>-which,
10+
// on clang+libstdc++, is also selected by __cpp_lib_expected under C++20.
11+
//
12+
// Therefore the polyfill below is used UNCONDITIONALLY on every platform.
13+
// Linux (clang + libstdc++), macOS (clang + libc++) and Windows (clang-cl +
14+
// MSVC STL) must all take the exact same branch, otherwise a hard error
15+
// appears only on Linux. All call sites use kyty::expected / kyty::unexpected.
1116
//
1217
// Exception-free: the project builds with -fno-exceptions on Linux/macOS, so
1318
// value()/error() on the wrong state assert() in debug builds instead of
1419
// throwing. (In release builds an unguarded wrong-state access trips the
1520
// variant's own error path - a loud failure, never silent UB.)
1621

17-
#include <version>
18-
19-
#if defined(__cpp_lib_expected) && __cpp_lib_expected >= 202202L
20-
21-
#include <expected>
22-
23-
namespace kyty {
24-
25-
using std::bad_expected_access;
26-
using std::expected;
27-
using std::unexpected;
28-
29-
template <class E>
30-
unexpected(E) -> unexpected<E>;
31-
32-
} // namespace kyty
33-
34-
#else
35-
3622
#include <cassert>
3723
#include <type_traits>
3824
#include <utility>
@@ -246,5 +232,3 @@ class expected<void, E> {
246232
};
247233

248234
} // namespace kyty
249-
250-
#endif

src/kyty_expected.hpp

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,19 @@
66
// Deliberately NOT defined in namespace std:
77
// * defining names in namespace std is undefined behavior,
88
// * libstdc++ >= 13 declares a legacy function `void std::unexpected()`
9-
// which would collide with a class template of the same name.
10-
// `kyty::expected` / `kyty::unexpected` are provided via using-declarations.
9+
// which collides with the real std::unexpected<T> from <expected>-which,
10+
// on clang+libstdc++, is also selected by __cpp_lib_expected under C++20.
11+
//
12+
// Therefore the polyfill below is used UNCONDITIONALLY on every platform.
13+
// Linux (clang + libstdc++), macOS (clang + libc++) and Windows (clang-cl +
14+
// MSVC STL) must all take the exact same branch, otherwise a hard error
15+
// appears only on Linux. All call sites use kyty::expected / kyty::unexpected.
1116
//
1217
// Exception-free: the project builds with -fno-exceptions on Linux/macOS, so
1318
// value()/error() on the wrong state assert() in debug builds instead of
1419
// throwing. (In release builds an unguarded wrong-state access trips the
1520
// variant's own error path - a loud failure, never silent UB.)
1621

17-
#include <version>
18-
19-
#if defined(__cpp_lib_expected) && __cpp_lib_expected >= 202202L
20-
21-
#include <expected>
22-
23-
namespace kyty {
24-
25-
using std::bad_expected_access;
26-
using std::expected;
27-
using std::unexpected;
28-
29-
template <class E>
30-
unexpected(E) -> unexpected<E>;
31-
32-
} // namespace kyty
33-
34-
#else
35-
3622
#include <cassert>
3723
#include <type_traits>
3824
#include <utility>
@@ -246,5 +232,3 @@ class expected<void, E> {
246232
};
247233

248234
} // namespace kyty
249-
250-
#endif

0 commit comments

Comments
 (0)