File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments