[英]Pass a constexpr char[] var to template param of struct and then use fmt to output will throw an exception?
example code示例代码
template<const char* str>
class MyStruct
{
public:
void Print()
{
cout << fmt::format("{}", str);
}
};
constexpr char szTest[] = "hello";
int main()
{
MyStruct<szTest> info;
info.Print();
return 0;
}
In practice, This code throws an exception in function 'basic_string_view(const Char* s)', I tried to replace constexpr with const, and then everything is ok.实际上,此代码在 function 'basic_string_view(const Char* s)' 中抛出异常,我尝试将 constexpr 替换为 const,然后一切正常。 Does anyone know why?
有谁知道为什么?
I want to know why constexpr cannot be used here, Is that the rule or a bug?我想知道为什么不能在这里使用 constexpr,这是规则还是错误?
More Info:更多信息:
OS: Windows操作系统:Windows
IDE: vs2019 (16.11.18) IDE:vs2019 (16.11.18)
C++ Language Standard: C++20 C++ 语言标准:C++20
Fmt version: 9.1.0 (The same problem exists with std::format) fmt版本:9.1.0(std::format存在同样的问题)
szTest
is a valid template non type argument for a parameter of type const char*
and the program is well-formed. szTest
是类型为const char*
的参数的有效模板非类型参数,并且程序格式正确。
Is that the rule or a bug?
这是规则还是错误?
Yes, this seems to be a msvc linker bug .是的,这似乎是一个msvc linker 错误。 Both gcc and clang execute the program without any problem.
gcc和clang执行程序都没有问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.