Thanks, Jonathan and Jakub.

You are right that my original explanation was incomplete. The issue
is not that bf16 is a GCC-specific literal; it is the standard
bfloat16 literal suffix, which clangd 18 and 19 currently reject when
they parse it:

invalid suffix 'bf16' on floating constant

This can occur when clangd parses GCC libstdc++ headers with the GCC
bfloat16 feature macros enabled. I also confirmed that replacing only
the use in <format> with __gnu_cxx::__bfloat16_t is not sufficient
justification by itself, because the typedef in bits/c++config.h is
currently defined using the same literal.

I will withdraw this patch and send a revised patch only after
verifying a complete fix, with a minimal reproduction and the clangd
version/configuration included in the commit message. I will also
avoid sending a 0/1 cover letter for a single patch.

Thanks,
Jakit

Jakub Jelinek <[email protected]> 于2026年9月7日周一 17:39写道:
>
> On Mon, Sep 07, 2026 at 10:14:39AM +0800, Jakit Liang wrote:
> > 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:
>
> Why would it parse it?
> From what I can see, clang++ doesn't predefine __BFLT16_DIG__ and other
> __BFLT16_* macros.
> Are you preprocessing with GCC and compiling with clang?
>
> > > > --- 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
>
>         Jakub
>

Reply via email to