据我所知,
constexpr
函数不能调用非constexpr
函数。但是,看起来在 clang 中,constexpr
函数可以调用 std::format()
(我知道它没有 constexpr
说明符)。
什么原因?为什么 clang 以不同的方式处理它们?
// It is compiled without any error
constexpr std::string print() {
return std::format("hello");
}
std::string myformat() {
return "hello";
}
// compiler error: non-constexpr function 'myformat' cannot be used in a constant expression
constexpr std::string myprint() {
return myformat();
}
两者在MSVC中都是ill-formed,报error C3615.