Skip to content

Re-enable compile-time format checks#3276

Merged
dschwoerer merged 3 commits intoc++20from
c++20-compile-time-fmt
Feb 27, 2026
Merged

Re-enable compile-time format checks#3276
dschwoerer merged 3 commits intoc++20from
c++20-compile-time-fmt

Conversation

@ZedThree
Copy link
Member

@ZedThree ZedThree commented Feb 17, 2026

This uses a C++23 feature if consteval if it's available to allow us to do compile-time format-string checking and use gettext's i18n. If if consteval isn't available, we fallback to just runtime checking.

This feature is actually useful -- this commit fixes some bugs in a few output messages where the wrong number of format arguments were being passed!

However, the cost of this is that I've had to introduce a new macro, _f, for gettext strings that are format-strings, because it doesn't play nice with output << _("something"). We should probably just deprecate and remove output << anyway, but I didn't fancy fixing all of that right now.

I've had to silence cppcoreguidelines-missing-std-forward in our formatting functions because fmt::make_format_args explicitly requires this de-optimisation to avoid lifetime issues.


Currently failing on CI because I think it does now actually need C++20 to build.

Now into #3265 so that we can start using C++20

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@ZedThree ZedThree force-pushed the c++20-compile-time-fmt branch from f64cbaa to d4260cf Compare February 24, 2026 15:26
@ZedThree ZedThree changed the base branch from c++20-ready to c++20 February 24, 2026 15:26
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@ZedThree ZedThree force-pushed the c++20-compile-time-fmt branch from d4260cf to f509b78 Compare February 24, 2026 16:02
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Mostly involves using `fmt::vformat` with `fmt::make_format_args` in
functions/ctors that act like `fmt::format`.

Note that `fmt::make_format_args` requires lvalues, so although we take `Args&&`
we _must not_ call `std::forward`.

We also have to introduce a new gettext macro `_f` to allow compile-time format
arg checking _and_ runtime i18n substitution.
@ZedThree ZedThree force-pushed the c++20-compile-time-fmt branch from f509b78 to 200e4ca Compare February 26, 2026 17:25
@ZedThree
Copy link
Member Author

@bendudson Any opinion on the new _f macro? I think we could do without it if we removed all uses of output <<, but there's a few hundred uses of that

@ZedThree
Copy link
Member Author

ZedThree commented Feb 26, 2026

Currently failing the CUDA build, but that's being updated elsewhere -- probably sensible to try and get that in first?

Actually this is a PR into another PR, so this one can be merged at least

@dschwoerer dschwoerer merged commit 50f06f7 into c++20 Feb 27, 2026
1 check passed
@dschwoerer dschwoerer deleted the c++20-compile-time-fmt branch February 27, 2026 08:57
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.

2 participants