为什么非 constexpr 函数可以在 Clang 中调用 std::format

问题描述 投票:0回答:0

据我所知,

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.

c++ format clang c++20 constexpr
© www.soinside.com 2019 - 2024. All rights reserved.