【发布时间】:2021-02-22 00:00:26
【问题描述】:
考虑以下代码。我可以用 GCC 10.2.0 和 Clang 11.0.0 编译它(如预期的那样):
#include <iostream>
template<int>
struct T {
static constexpr auto fun() noexcept { return 0; }
using type = std::remove_cvref_t<decltype(fun())>;
};
int main() {
decltype(T<1>::fun()) a = 1;
std::cout << a;
}
如果我将 constexpr 替换为 consteval,那么 Clang 会抱怨 std::remove_cvref_t<decltype(fun())>:
错误:不能在立即调用之外获取 consteval 函数 'fun' 的地址
GCC 编译它就好了。为什么?
【问题讨论】: