Hi Jonathan, Thanks for the review.
There is nothing inherently wrong with the `0.0bf16` literal when compiled by GCC. The issue is that it is only used here to obtain the bfloat16 type, but exposing this GCC-specific literal in the libstdc++ header causes problems for Clang-based tooling such as clangd. For example, when clangd parses and instantiates `_S_to_arg_type` for an ordinary `std::format` call, it can produce: ``` 'auto' in return type deduced as 'type_identity<const char *>' but deduced as 'type_identity<float>' in an earlier return statement ``` GCC itself compiles the code correctly. Using `__gnu_cxx::__bfloat16_t` directly expresses the same type check without requiring the parser to handle the bf16 literal, so the bfloat16-to-float normalization is unchanged. I think this is useful on the gcc-14 release branch because GCC 14's libstdc++ headers are consumed by Clang/clangd tooling, and this results in diagnostics for otherwise valid `std::format` code. The change is limited to the internal type check and does not change ABI or runtime behaviour. I'll also avoid sending a `[PATCH 0/1]` cover letter for a single patch and put the explanation in the commit message. Thanks, Jakit Jonathan Wakely <[email protected]> 于2026年9月7日周一 00:44写道: > > Please don't send a [PATCH 0/1] cover letter for a patch "series" of > one patch. Just put the explanation in the patch's commit message, > instead of saying the same thing in two places, with slightly > different wording. > > Also, despite writing two cover letters and two commit messages, you > didn't explain why this is a desirable change. What's wrong with the > literal? And why should we change this now on the gcc-14 release > branch? > > > On Sat, 5 Sept 2026 at 22:02, Jakit Liang <[email protected]> wrote: > > > > In std::basic_format_arg::_S_to_arg_type, replace the bfloat16 > > normalization check that uses decltype(0.0bf16) with > > __gnu_cxx::__bfloat16_t. > > > > This preserves existing behavior (normalizing to float) while avoiding a > > direct bf16 literal-based type check in <format>. > > > > Signed-off-by: Jakit Liang <[email protected]> > > --- > > libstdc++-v3/include/std/format | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/libstdc++-v3/include/std/format > > b/libstdc++-v3/include/std/format > > index ada62c26bca..52136c9fd76 100644 > > --- a/libstdc++-v3/include/std/format > > +++ b/libstdc++-v3/include/std/format > > @@ -3373,7 +3373,7 @@ namespace __format > > #endif > > > > #if defined(__BFLT16_DIG__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32) > > - else if constexpr (is_same_v<_Td, decltype(0.0bf16)>) > > + else if constexpr (is_same_v<_Td, __gnu_cxx::__bfloat16_t>) > > return type_identity<float>(); > > #endif > > > > -- > > 2.47.3 > > >
