Skip to content

Switch to C++23 - #75

Open
leoetlino wants to merge 14 commits into
zeldamods:masterfrom
leoetlino:cpp23
Open

leoetlino wants to merge 14 commits into
zeldamods:masterfrom
leoetlino:cpp23

Conversation

@leoetlino

@leoetlino leoetlino commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Not sure what compiler support is like, let's see.


This change is Reviewable

C++23 explicit object parameters need GCC 14, but ubuntu-latest still
defaults to GCC 13. The manylinux_2_28 image used for release wheels
already ships GCC 14.
Allows C++23 features in the bindings. The unqualified forward_like
call in the vendored visit.h becomes ambiguous with std::forward_like
under C++23, so qualify it like the other call site in that file.

CMake only accepts C++23 as a standard from 3.20 on, so require it.
Every borrowable type repeated the same isinstance/borrow/restore
block. A recursive lambda over (type, enum) tags keeps one copy while
still returning the callable's result directly, void included.
The Python module already builds as C++23 and compiles the core sources
with it, so standalone builds were the only ones still on C++20. Moving
the core target up lets the library itself use deducing this,
std::byteswap and friends.

CMake only knows cxx_std_23 from 3.20 on, so require it here too.
The platform #ifdef ladder over compiler and OS byte swap intrinsics,
and the runtime htonl probe for the host byte order, are what
std::byteswap and std::endian now provide portably; they also drop the
POSIX-only headers from a public include. The swap8/16/24/32/64
helpers and their pointer-based forms had no users in oead and are
removed; C++ callers should use std::byteswap.

Checked against the old implementation on integer, float and NaN bit
patterns with zero mismatches.
BitCast was a pre-C++20 stand-in for std::bit_cast and went through
std::aligned_storage, which C++23 deprecates. The standard version is
also constexpr. C++ callers of util::BitCast should switch to
std::bit_cast.
The two overloads had identical bodies. With deducing this one
definition serves both; std::forward_like keeps the boxed alternatives
const for a const Variant, since dereferencing a const unique_ptr would
otherwise yield a mutable reference.
Each of GetHash, GetArray, GetString and GetBinary had a const and a
non-const overload defined out of line, all forwarding to Get. A single
inline member per getter now covers both. Being templates, they can no
longer be named as member function pointers (py::overload_cast,
static_cast to a pointer type), so get_string is bound through a lambda.
Each pair had identical bodies. One deducing-this member per accessor
keeps the result's constness tied to the object, as Variant::Get does,
and still accepts rvalues. Like the container getters, they can no
longer be named as member function pointers.
The two overloads differed only in whether the result referred to a
const value. Deducing this picks that from the object, so a const Byml
still yields Reference<const T>. The template parameter no longer
shadows the Type enum.
std::to_underlying states the intent of these enum-to-integer
conversions directly and can't drift from the enum's actual underlying
type the way a spelled-out cast can.
The standard member does the same single-character search without
pulling in absl/strings/match.h, which yaml.cpp no longer needs.
ExtractBit(s), RotateLeft/Right, IsValidLowMask, SetBit, BitSize and
BitCastToArray/FromArray came over from Dolphin with this header but
nothing in oead uses them, and std::rotl/std::rotr and std::bit_cast
now cover what they offered.
Nothing in oead calls them; std::ranges::contains now covers Contains,
and keeping a const_cast helper around only invites misuse.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant