186 Commits

Author SHA1 Message Date
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
Martin Storsjö
758d39eb23
Add a missing include for the C++ module build (#4868)
The std.h header uses types such as std::atomic and std::atomic_flag.
For the normal build mode, this header does include all the
headers it needs, such as <atomic>.

However when building the C++ module of {fmt}, the std.h header
omits such includes, and instead expects them to be included
beforehand by fmt.cc - which lacked including <atomic>.

This fixes building the C++ module with libc++ 23, which has removed
a number of unnecessary transitive includes.
2026-07-29 12:23:12 -07:00
Victor Zverovich
c1c7296bfa Add a test for fmt_print 2026-06-08 08:18:43 +02:00
Ferdinand Bachmann
ffd8397db1
Add fmt_print to C API (#4789)
* Add FMT_FORMAT_ARGS(fmt, ...) macro to C API to simplify user-defined format wrappers

* Add fmt_print to C API
2026-06-05 06:40:30 -07:00
Victor Zverovich
46cf422f54 Unify copyright notices 2026-05-31 08:54:06 -07:00
Kağan Can Şit
d0e3d20af8
chore(IWYU):Remove redundant includes (#4758) 2026-04-29 20:50:56 -07:00
st0rmbtw
4b50ad7944
Replace try and catch with the FMT_TRY and FMT_CATCH macros (#4751) 2026-04-20 10:29:42 -07:00
mccakit
3febdca556
clang compilation failiure fix (#4718) 2026-04-02 16:51:38 -07:00
Victor Zverovich
4968433a6a Minor cleanup 2026-03-16 14:34:20 -07:00
Victor Chernyakin
e8244777ee
Move a few classes into an anonymous namespace (#4713) 2026-03-15 07:33:33 -07:00
Victor Zverovich
60d5d0cec6 Workaround broken _Generic in MSVC 2026-02-21 15:04:38 -08:00
Victor Zverovich
9e5bb7ef77 Cleanup the C API 2026-02-21 11:46:23 -08:00
Soumik15630m
1dc644e021
Add C11 API with type-safe formatting (#4663) (#4671) 2026-02-16 07:06:32 -08:00
Victor Zverovich
e8da5ba275 Fix formatting 2025-10-19 10:22:39 -07:00
Victor Zverovich
e2aa06cd0a Workaround ABI incompatibility between clang ang gcc 2025-10-19 08:40:13 -07:00
Victor Chernyakin
80549a630e
Avoid repeated call to GetLastError in file::size (#4522) 2025-09-03 08:38:31 -07:00
Victor Zverovich
16d371b649 Apply clang-tidy 2025-09-01 12:00:35 -07:00
Victor Zverovich
13d4f8469e Remove deprecated vformat_to 2025-08-31 10:02:36 -07:00
Victor Zverovich
489fd7ca4b Simplify locale handling 2025-08-31 09:33:43 -07:00
anonymous
20c8fdad06
Fix import std in clang++ (#4488)
fix module-compilation error when defined `FMT_IMPORT_STD`
2025-07-07 11:47:48 -07:00
Victor Zverovich
b43b2f9537 Cleanup standard formatters 2025-05-04 13:04:06 -07:00
Victor Zverovich
c43da35701 Workaround an ICE when using modules with gcc 14.2 and earlier 2025-01-12 08:57:43 -08:00
Victor Zverovich
891c9a73ae Cleanup format API 2024-09-22 15:52:55 -07:00
Victor Zverovich
e5b20ff0d0 Deprecate detail::locale_ref 2024-09-22 10:44:38 -07:00
Victor Zverovich
b52fb98846 Fix no locale build 2024-09-11 20:37:44 -07:00
Victor Zverovich
a2c290bc34 Suppress a bogus MSVC warning 2024-09-04 17:20:30 -07:00
Victor Zverovich
c3344e21e2 Cleanup base API 2024-09-04 15:50:53 -07:00
Victor Zverovich
020af729dd Simplify ostream 2024-08-17 08:38:10 -07:00
Victor Zverovich
58aba5a3de Deprecate append instantiation 2024-08-03 11:55:25 -07:00
Cameron Angus
52b32081f9
Wrap private module fragment content within conditional extern "C++", to match declarations. (#4083) 2024-07-24 06:25:23 -07:00
Matthias Moulin
bbf44cc000
Defines are still needed for FMT_MODULE as well (#4027) 2024-06-24 07:11:35 -07:00
Matthias Moulin
af8cd4e404
Module purview can only contain direct preprocessor code (#4029)
Resolved MSVC Warning C5202: a global module fragment can only contain preprocessor directives
2024-06-19 13:00:29 -07:00
LoveSy
8687315e86
Guard more system headers by FMT_MODULE (#4006)
* Guard more system headers by `FMT_MODULE`

* Merge FMT_MODULE and FMT_IMPORT_STD
2024-06-14 10:53:51 -07:00
LoveSy
51a690ab15
Check if .cc exists in fmt.cc (#4005)
After installation, these files no longer exist and cause errors.
2024-06-09 18:01:44 -07:00
LoveSy
0f6e716548
Fix missing includes in fmt.cc (#3994)
This causes duplicated std definitions in the fmt module
2024-06-08 13:50:29 -07:00
Jiwoo Park
f4b256c667 Fix warning C26439 2024-04-19 09:06:46 -07:00
Matthias Moulin
aa52eb765d
Resolved warning C4996: 'fileno': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _fileno. (#3930) 2024-04-11 11:13:57 -07:00
Matthias Moulin
116a9ce488
Added FMT_IMPORT_STD feature macro (#3928) 2024-04-10 11:48:32 -07:00
Victor Zverovich
38881e5acf Fix handling of the fileno macro 2024-03-20 05:06:36 +09:00
Vladislav Shchapov
7fd1802686
Fix FMT_OS definition (#3783)
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
2024-01-02 07:20:09 -08:00
Victor Zverovich
63ce170853 Replace virtual dispatch with normal functions in buffers 2024-01-02 07:02:20 -08:00
Victor Zverovich
9659f22d36 Don't include os.cc in the module if it is disabled via FMT_OS 2024-01-01 18:32:53 -08:00
Victor Zverovich
c142385033 Improve the pipe API 2024-01-01 15:55:37 -08:00
Victor Zverovich
398ddb8fec Don't include fmt/os.h in the module if it is disabled via FMT_OS 2024-01-01 12:21:28 -08:00
Kefu Chai
6855bd532b Apply clang-format
* use clang-format v17.0.6 to reformat the tree
* tweak some places so that clang-format does not mutate the layout
  of code too much

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
2023-12-13 07:18:37 -08:00
Victor Zverovich
6b0082e6c7 Improve OpenBSD workaround 2023-11-07 09:24:33 -10:00
Christoph Reiter
b3bf23f3c4
Remove leftover usage of the __std_stream header (#3663)
2dd4fa8742fdac36468f8d removed all usage of __std_stream because
it is no longer available with clang v17. That commit missed one place
where the header was still used (only used when building with -DFMT_MODULE=ON).
Remove it there too.

See #3654
2023-10-01 08:16:42 -07:00
Victor Zverovich
0f823df46a Remove detail namespace hack 2023-06-04 15:19:50 -07:00
Victor Zverovich
b2106f3639 Tweak comments 2023-05-31 09:52:44 -07:00
Bin Lan
61fb3a15ff
Add VxWorks7 user space and kernel space support (#3467) 2023-05-31 06:35:07 -07:00