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!

0

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.

0

请先登录再写评论。