CLion's bundled clangd 18 diagnoses the standard bf16 literal suffix in
the GCC 14 <format> header when analyzing a WSL project with a GCC
toolchain:

  invalid suffix 'bf16' on floating constant

Avoid using the literal merely to name its type. Define
__gnu_cxx::__bfloat16_t using the GCC __bf16 type and use that alias in
the <format> internal bfloat16 alias. __bf16 and decltype(0.0bf16)
denote the same type, so this preserves the existing bfloat16 formatting
behavior.

Tested on x86_64-linux-gnu with g++ and clangd 18/19.

Signed-off-by: Jakit Liang <[email protected]>
---
 libstdc++-v3/include/bits/c++config | 2 +-
 libstdc++-v3/include/std/format     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/bits/c++config 
b/libstdc++-v3/include/bits/c++config
index 60456a48681..072da451df8 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -892,7 +892,7 @@ namespace std
 #if defined __cplusplus && defined __BFLT16_DIG__
 namespace __gnu_cxx
 {
-  typedef __decltype(0.0bf16) __bfloat16_t;
+  typedef __bf16 __bfloat16_t;
 }
 #endif
 
diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index 8d530e883c3..deb9d398844 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -1919,7 +1919,7 @@ namespace __format
     };
 
 #ifdef __BFLT16_DIG__
-   using __bflt16_t = decltype(0.0bf16);
+   using __bflt16_t = __gnu_cxx::__bfloat16_t;
 #endif
 
   // Decide how 128-bit floating-point types should be formatted (or not).
-- 
2.47.3

Reply via email to