Issues with std::format in CLion 2024.3: Incorrect Template Deduction and Errors Related to const char*, std::string and bf16
Hi everyone,
I'm facing an issue with std::format in CLion 2024.3. For the following code:
#include <iostream>
#include <format>
#include <string>
int main() {
std::cout << std::format("Hello, {}!\n", "World");
return 0;
}
CLion complains at std::format :
In template: 'auto' in return type deduced as 'type_identity<const std::basic_format_arg<std::basic_format_context<std::__format::_Sink_iter<char>, char>>::_CharT *>' (aka 'type_identity<const char *>') here but deduced as 'type_identity<float>' in earlier return statement
...
so I jumped there and check why it produced a float. After looking into the code around the error, I noticed the issue seems to be related to a conditional block in the GCC-provided standard library headers format:
#if defined(__BFLT16_DIG__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
else if constexpr (is_same_v<_Td, decltype(0.0bf16)>)
return type_identity<float>();
#endif
...
else if constexpr (is_same_v<decay_t<_Td>, const _CharT*>)
return type_identity<const _CharT*>();
else if constexpr (is_same_v<decay_t<_Td>, _CharT*>)
return type_identity<const _CharT*>();
It seems like CLion is not handling this properly, as it gives an error at 0.0bf16 saying that Invalid suffix 'bf16' on floating constant . This may be affecting the template deduction process, causing the incorrect deduction of const char* and leading to the error above.
When I manually compile the same code using GCC (version 14.2.1), there are no issues at all, which makes me think this could be a problem with how CLion is handling the standard library or template deduction.
I've also tried replacing const char* with std::string and encountered similar issues, but switching to basic types like int or float works fine.
Has anyone else experienced a similar issue with std::format in CLion? Any advice on how to fix this or work around it?
Thanks in advance for any help!
请先登录再写评论。
Hello!
Please enable the Nova engine - https://www.jetbrains.com/help/clion/clion-nova-introduction.html. On my side, it doesn't produce the error.
After updating to 20215.2 (Build #CL-252.23892.426, built on August 2, 2025) today (with Nova enabled), I have this exact problem with clangd, also in std::format (via std::println):
(all 3 arguments are std::string_view) Gives:
and
Again, (arguments are std::string_view) gives:
All code compiles fine however. I can disable Clangd but that seems suboptimal?
CLion 2025.2Build #CL-252.23892.426, built on August 2, 2025Source revision: fe91b356294c0For my code that otherwise compiles fine, the IDE highlights all calls to std::format as errors
Using a method that indirectly invokes std::format:
Clangd: In template: 'auto' in return type deduced as 'type_identity<double>' here but deduced as 'type_identity<float>' in earlier return statementpublic methodstatic void trace<Args...>(spdlog::format_string_t<Args...> fmt,Args&&... args)in struct DeclaredLogger<NameProvider>and with std::format directly:
Clangd: In template: no member named '_M_dbl' in 'std::__format::_Arg_value<std::basic_format_context<std::__format::_Sink_iter<char>, char>>'functioninline string format<_Args...>(format_string<_Args...> __fmt,_Args&&... __args)in namespace stdusing Nova Engine and compiler is GCC 13.3.0. Pretty sure I get the same error on MSVC as well.
Jon Cppl, it looks like CPP-42195. It should be fixed in the first CLion 2025.3 EAP build, which is tentatively scheduled for release this week.