Skip to content

Comments

Re-enable compile-time format checks#3276

Open
ZedThree wants to merge 1 commit intoc++20from
c++20-compile-time-fmt
Open

Re-enable compile-time format checks#3276
ZedThree wants to merge 1 commit 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

template <class... Args>
// NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward)
MsgStackItem(const std::string& file, int line, fmt::format_string<Args...> msg,
Args&&... args)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: forwarding reference parameter 'args' is never forwarded inside the function body [cppcoreguidelines-missing-std-forward]

               Args&&... args)
                         ^

@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


#include <algorithm>
#include <clocale>
#include <csignal>
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: included header clocale is not used directly [misc-include-cleaner]

Suggested change
#include <csignal>
#include <csignal>

src/bout++.cxx Outdated
#include <signal.h>
#include <sstream>
#include <stdexcept>
#include <stdio.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: included header stdexcept is not used directly [misc-include-cleaner]

Suggested change
#include <stdio.h>
#include <stdio.h>

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 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

#include <signal.h>
#include <sstream>
#include <stdexcept>
#include <string>
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: included header stdexcept is not used directly [misc-include-cleaner]

Suggested change
#include <string>
#include <string>

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