I'm a bit stumped as to why this code has suddenly stopped compiling: https://godbolt.org/z/hhM5GG78x
But if I change the compiler back v19.31, it will compile: https://godbolt.org/z/11j8WbEzG
Here's the code in question:
#include <format>
#include <string>
template <typename... Args>
void FormatString(const std::string_view& fmt_str, Args&&... args)
{
puts(std::format(fmt_str, args...).c_str());
}
int main()
{
FormatString("This is a {}.\n", "test");
return 0;
}
Here's the error message I'm receiving:
<source>(7): error C7595: 'std::_Basic_format_string<char,const char (&)[5]>::_Basic_format_string': call to immediate function is not a constant expression
<source>(7): note: failure was caused by a read of a variable outside its lifetime
<source>(7): note: see usage of 'fmt_str'
<source>(12): note: see reference to function template instantiation 'void FormatString<const char(&)[5]>(const std::string_view &,const char (&)[5])' being compiled
It's complaining about fmt_str being used outside of it's lifetime. I'm failing to see how this is the case?