fmt/support
Avi Kivity e27cc20bd9
Format enums annotated with fmt::as_identifiers (requires C++26 reflection) (#4885)
* Format enums annotated with fmt::as_identifiers (requires C++26 reflection)

Format an enum as the identifier of the matching enumerator if the enum is
annotated with fmt::as_identifiers:

  enum class [[=fmt::as_identifiers]] color { red, green, blue };
  fmt::format("{}", color::green);  // "green"

Values that don't match any enumerator are represented as their underlying
value in decimal before applying string formatting.

Identifiers are retrieved via C++26 reflection (P2996) and the annotation
via P3394. FMT_USE_REFLECTION is autodetected and can be overridden by the
user; without reflection the header is empty.

The header is also part of the fmt module, but, unlike with headers, whether
it provides anything is decided when the module is compiled, so the module
build detects reflection and enables it if the configured standard allows.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Look up enum identifiers by index when the values are dense

The formatter for enums annotated with fmt::as_identifiers did a linear
search over all enumerators. Build a table indexed by the distance from
the smallest enumerator value instead, with empty string views in the
holes, which reduces the lookup to a bounds check and one load.

The table is only used if at least 70% of its elements are identifiers,
limiting its size to 10/7 of the number of enumerators. Sparser enums
keep using the linear search. Distances are computed in uint64_t so that
enums with negative values and values spanning the whole range of the
underlying type are handled without overflow.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Suppress -Wsfinae-incomplete in format-test on GCC 16

GCC 16 warns when a type is completed after it failed to be complete in a
SFINAE context. format-test does this deliberately to check that formatting
of incomplete types works, so the warning is a false positive there and
breaks the build with -Werror.

* Test GCC 16 on CI

GCC 16 is the first compiler with C++26 reflection support, which is needed
by fmt/enum.h, so add a job that builds with it in C++26 mode. It comes from
the ubuntu-toolchain-r/test PPA since Ubuntu 24.04 only ships GCC 14.

Also report when reflection is not detected to make it visible that
enum-test was skipped.

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-23 09:31:28 -07:00
..
cmake Add pkgconfig file for fmt-c library (#4887) 2026-08-23 07:50:04 -07:00
gradle/wrapper Minor cleanup 2026-01-22 11:24:08 -08:00
python/mkdocstrings_handlers/cxx Format enums annotated with fmt::as_identifiers (requires C++26 reflection) (#4885) 2026-08-23 09:31:28 -07:00
Android.mk
AndroidManifest.xml Update Android Gradle Plugin to 9.x (#4658) 2026-01-21 10:22:00 -08:00
build.gradle Minor cleanup 2026-01-22 11:24:08 -08:00
C++.sublime-syntax
check-commits Update check-commits script 2024-07-17 06:58:37 -07:00
cmake-format-requirements.txt Pin deps 2026-05-31 19:10:01 -07:00
doc-requirements.in Pin doc deps 2026-05-31 20:14:10 -07:00
doc-requirements.txt Bump pymdown-extensions in /support in the pip group across 1 directory (#4881) 2026-08-09 08:42:05 -07:00
docopt.py
gradle.properties Minor cleanup 2026-01-22 11:24:08 -08:00
llvm-snapshot.gpg.key Pin clang-format install 2026-05-31 20:56:33 -07:00
mkdocs Restore api.html redirect to fix broken deep links 2026-06-05 08:06:58 -07:00
mkdocs.yml Disable footer 2024-06-09 19:02:34 -07:00
printable.py Supporting ? as a string presentation type (#2674) 2022-01-30 08:55:28 -08:00
README Update readme 2020-10-25 09:04:39 -07:00
release.py Attach release artifacts to draft via workflow_dispatch 2026-06-08 07:48:52 +02:00
Vagrantfile Update vagrant config 2024-06-30 07:56:35 -07:00

This directory contains build support files such as

* CMake modules
* Build scripts