7993 Commits

Author SHA1 Message Date
Victor Zverovich
44f2c7ae01 Make base.h a compatibility header
Complete the header swap by making core.h canonical and updating code, tests, documentation, and tooling.
2026-09-07 17:11:35 -07:00
Victor Zverovich
e2ef4c01b2 Move the core API back to core.h
base.h was introduced as a temporary migration path; restore the primary header's original name.
2026-09-07 17:05:39 -07:00
Victor Zverovich
5543473f5e Move the compatibility header aside
Free up core.h so base.h can be renamed back with its history preserved.
2026-09-07 17:05:32 -07:00
Victor Zverovich
d3b2fac5c9 Simplify exception_ptr fallback formatting 2026-09-07 15:36:06 -07:00
IfkumRfnl
8a7aea0422
Fix out-of-bounds read in error code format parsing (#4934) 2026-09-07 11:35:29 -07:00
Victor Zverovich
7071103cea Remove incorrect chrono padding claim 2026-09-07 07:59:32 -07:00
Wu Shuwen
7fe204caed
Correct locale support in size optimization docs (#4923) 2026-09-07 07:17:52 -07:00
Jacek Caban
c07e2aa4b1
Disable std::exception_ptr and nested_exception formatters when exceptions are disabled. (#4904)
Fixes building with Clang 20 and older with -fno-exceptions, which treats
try/catch usage as an error.
2026-09-07 07:13:51 -07:00
Ethan Stoner
2d4d8a13c2
Build nolocale-test with /utf-8 on MSVC (#4919)
nolocale-test compiles src/format.cc directly, so it does not pick up the
/utf-8 that CMakeLists.txt adds to the fmt target. On MSVC the static_assert
in base.h then fires: "Unicode support requires compiling with /utf-8".

The target only exists under FMT_PEDANTIC, which the Windows workflow does not
set, so this has not shown up in CI. unicode-test already guards the same flag
the same way.
2026-09-06 13:46:11 -07:00
Victor Zverovich
8be4b46114 Bump mkdocs-material to 9.7.7 2026-09-06 12:26:04 -07:00
Alexander
67ae943b12
Add Quill to the list of notable users (#4931)
One of its unique features is that it serializes the format
string and all format arguments to the thread's SPSQ queue
to minimize processing on hotpath and then deserializes them
on the backend thread which performs formatting using {fmt}
and writing to the log sinks.

Signed-off-by: Alexander Lobakin <alobakin@mailbox.org>
2026-09-06 10:48:02 -07:00
Victor Zverovich
4fcb22bf65 Clarify compile-time benchmark results 2026-09-06 10:25:41 -07:00
Victor Zverovich
d0aae8c15a Refactor range outer formatting 2026-09-06 10:01:08 -07:00
Avionic Harshit
61e3b92396
Support fill, alignment and width in range and tuple formatters (#4910) 2026-09-06 08:47:40 -07:00
Wu Shuwen
0f3c5fd596
Fix the chrono format specification link (#4927) 2026-09-05 15:40:30 -07:00
Victor Zverovich
d90c33606c Apply cmake-format 2026-09-05 08:51:28 -07:00
Dylan Pulver
a389757209
Remove the '0' chrono padding modifier from the docs (#4917)
The '0' modifier was documented in ca8eeb09 (#3976) and the parser case for
it was removed nine days later in 7bd11b5c ("Remove a redundant extension to
reduce divergence from std::format"), which did not update the docs. Since
then the grammar and the modifier table have promised a modifier that
parse_chrono_format rejects with "invalid format", for all 11 of the
presentation types the same section lists as supporting it.

Zero padding remains the default, so the extension really was redundant;
this only aligns the documentation with the code.

Co-authored-by: Dylan Pulver <dylanpulver@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
2026-09-05 08:33:43 -07:00
Victor Zverovich
de3660a745 Update compile-time benchmark results 2026-09-05 07:20:53 -07:00
Victor Zverovich
6226bc70b8 Enable modules by default with AppleClang 2026-09-04 16:16:19 -07:00
Victor Zverovich
3a110201c9 Use named module file option 2026-09-04 15:49:10 -07:00
Victor Zverovich
40c4f4febb Fix fcntl include in module build 2026-09-04 15:46:08 -07:00
Victor Zverovich
3894ae35ef Fix AppleClang module build 2026-09-04 15:31:24 -07:00
Victor Zverovich
1dd74c0c82 Reorder performance comparison 2026-09-04 12:54:13 -07:00
Victor Zverovich
ba24da597a Simplify performance overview 2026-09-04 12:28:26 -07:00
Victor Zverovich
8bd6079278 Update compile-time benchmark results 2026-09-04 12:13:45 -07:00
Konstantin Goncharuk
fb1a3ef342
docs: add link to a live browser demo (#4916) 2026-09-04 12:01:07 -07:00
Victor Zverovich
ce039d14fe Move migration guidance to documentation 2026-09-04 09:37:28 -07:00
Satyakam Mishra
b4b1657c2a
Fix debug format width calculation (#4902) 2026-09-04 09:17:58 -07:00
Victor Zverovich
ff4a0fdfb9 Streamline README 2026-09-04 09:13:02 -07:00
Victor Zverovich
2e6c5741d2 Move display width table out of function 2026-09-04 08:44:26 -07:00
Victor Zverovich
bc82c408a6 Test dynamic width in nested_formatter 2026-09-02 10:53:56 -07:00
Victor Zverovich
cbb264122a Simplify nested_formatter context handling
Format nested values directly through the stored formatter so dynamic
specifications resolve against the enclosing operation.
2026-09-02 10:14:09 -07:00
dependabot[bot]
c5728fb720
Bump msys2/setup-msys2 from 2.28.0 to 2.32.0 (#4908)
Bumps [msys2/setup-msys2](https://github.com/msys2/setup-msys2) from 2.28.0 to 2.32.0.
- [Release notes](https://github.com/msys2/setup-msys2/releases)
- [Changelog](https://github.com/msys2/setup-msys2/blob/main/CHANGELOG.md)
- [Commits](40677d36a5...66cd2cce69)

---
updated-dependencies:
- dependency-name: msys2/setup-msys2
  dependency-version: 2.32.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-09-01 10:51:53 -07:00
LJX1021403
1931ff7244
Fix typo: format-benchmarks -> format-benchmark (#4906)
Fix typo: repository name is "format-benchmark" (singular), not "format-benchmarks".
2026-09-01 10:50:09 -07:00
way4sahil
b039e624c0
Document C++20 module usage with CMake (#4891)
* Document C++20 module usage with CMake

* Added Change log

* Addressed review comments

---------

Co-authored-by: Sahil Sinha <sahil.sinha@stryker.com>
2026-08-30 10:17:00 -07:00
Tiago
f87405f21d
Suppress unused parameter warnings with FMT_USE_LOCALE=0 (#4903)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-08-30 08:37:51 -07:00
Avi Kivity
fa9590f63f
Apply clang-format to enum.h (#4905)
Recent changes moved away from the blessed layout.
2026-08-30 08:16:33 -07:00
Eduardo Gómez
d0cec7ae2e
Fix inconsistent display width for emoji outside East Asian Wide ranges (#4896)
* Widen display_width_of() to cover Emoji_Presentation code points

fmt::detail::display_width_of() only treated East Asian Wide/Fullwidth
code points and two hand-picked emoji ranges as two columns wide, so
emoji outside those ranges (e.g. the Dingbats block: cross mark U+274C,
white heavy check mark U+2705) were measured as one column even though
most terminals render them double-width. This produced visibly
inconsistent padding under {:^N} compared to CJK text (fixes #4851).

Replaced the ad hoc boolean expression with a sorted table of ranges
(East Asian Wide/Fullwidth plus the full Emoji_Presentation set from
Unicode's emoji-data.txt) looked up via binary search, and added
regression tests covering the original report plus edge cases:
multiple emoji, mixed emoji/CJK/ASCII content, precision truncation,
alignment/fill variants, newly covered emoji ranges, and regional
indicator (flag) pairs.

* Make wide_cp_ranges C++11-compatible; apply clang-format

* Move wide_cp_range struct into display_width_of()

* Derive wide_cp_ranges from East_Asian_Width data, restore constexpr

* Move wide_cp_ranges to display_width_of function body

* Update format.h

* Update wide_cp_ranges array to include comments

* Add inline to display_width_of and add 1F300-1F5FF and 1F900-1F9FF ranges to match [format.string.std]

* Update display_width_of lo hi varible declaration

---------

Co-authored-by: Eduardo Gomez Saldias <50159560+edugomez102@users.noreply.github.com>
2026-08-30 08:05:50 -07:00
Victor Zverovich
bb1bcede25 Stop enabling C++26 reflection by default
Don't inject -freflection when building the module, so it isn't forced onto
the module or its importers. Build enum-test unconditionally (it is a no-op
without reflection) and drop the now-unneeded reflection detection. Enable
reflection explicitly in the g++-16 C++26 CI job.
2026-08-29 16:28:09 -07:00
Victor Zverovich
9375eb3792 Simplify enum identifier handling and tidy reflection docs
Use std::string_view directly for enumerator identifiers, dropping the
identifier wrapper and inlining count_enumerators. Update the fmt/enum.h
documentation to point at cppreference and drop an inaccurate note. Also
remove the no-longer-needed -Wno-sfinae-incomplete option for format-test.
2026-08-29 15:11:31 -07:00
TheNonConformist
8a84280f26
Suppress GCC 16 incomplete type warning (#4893) 2026-08-29 15:09:36 -07:00
Avi Kivity
e589a16ecb
Look up sparse enum identifiers in a hash table instead of a linear search (#4899)
Enums that are too sparse for the index table were formatted by scanning
all enumerators. Replace the scan with an open-addressed hash table with
linear probing, sized to the smallest power of two that keeps the load
factor at or below 0.5. This guarantees a free slot, which terminates the
probe sequence and doubles as the not-found result because identifiers
are never empty.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-29 07:47:28 -07:00
Advit Arora
e76a9520a3
Right-align inf and nan with a bare width (#4895)
fmt::format("{:6}", nan) gave "nan   " where std::format and printf("%6f")
give "   nan". write_nonfinite was the only numeric write path taking
write_padded's align::left default, so a width with no explicit align
left-aligned inf and nan while every finite value right-aligned. That
default only reaches align::none, leaving explicit <, > and ^ and the 0
flag unchanged.
2026-08-27 08:54:40 -07:00
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
Ferdinand Bachmann
488c3b9628
Add pkgconfig file for fmt-c library (#4887) 2026-08-23 07:50:04 -07:00
Victor Zverovich
21d4cc15c8 Reject sign-aware zero padding in std::exception and error_code formatters
Treat a leading '0' as the zero flag rather than the start of the width so
it is rejected (as in the core formatter) instead of being silently consumed.
Also trim the exception_align test to the cases this actually introduces.
2026-08-16 10:00:41 -07:00
egorkaa
cde18a38bb
Support width and alignment in std::exception formatter (#4860)
* Support width and alignment in std::exception formatter

The formatter for std::exception (and std::exception_ptr) previously
accepted only the optional 't' type-name specifier, so standard fill,
align and width specifiers were rejected with "unknown format
specifier". This made it impossible to pad or align exception messages,
e.g. when laying them out in a log column.

Parse the standard fill/align/width specifiers (as the std::filesystem::
path formatter already does) and apply them when writing the message.
Dynamic width ({:{}}) and the 'none'/'unknown exception' cases for
exception_ptr are handled too. Existing behavior ({}, {:t}, nested
exception unwinding) is unchanged.

* Update std.h
2026-08-13 11:00:46 -07:00
Victor Zverovich
be39437ee7 Simplify hexfloat comment and retry CI downloads on more 50x errors 2026-08-12 09:21:04 -07:00
hexonal
6c285ba88a
Format zero as 0x0p+0 in hexfloat (#4878)
fmt::format("{:a}", 0.0) produced 0x0p-1022 where printf's %a gives
0x0p+0, and likewise for -0.0, {:A}, {:#a} and any explicit precision.

basic_fp::assign maps a zero biased exponent to 1 ("subnormals use
biased exponent 1"), which is right for subnormals but not for zero, so
format_hexfloat inherited the minimum subnormal exponent for a value
whose significand carries no information. Reset the exponent there
rather than in assign, which the decimal path shares.

A zero significand can only come from +-0: normals get the implicit bit
added, and a subnormal has a nonzero significand by definition. So the
guard cannot affect anything else, and denorm_min keeps its existing
denormalized form (0x0.0000000000001p-1022, asserted in format_double).

The five new expectations were taken from printf rather than derived,
and all fail without this change.
2026-08-10 09:52:03 -07:00
Victor Zverovich
0cf9f5c99e Rename loc_copy to locale in locale helpers (#4876) 2026-08-10 09:12:29 -07:00