类无法访问自己的私有静态 constexpr 方法 - Clang bug?

Class can't access its own private static constexpr method - Clang bug?

本文关键字:方法 constexpr Clang bug 静态 访问 自己的      更新时间:2023-10-16

这段代码不能在Clang(6,7,8,9,trunk(中编译,但在GCC(7.1,8.1,9.1(中编译得很好:

template<class T> struct TypeHolder { using type = T; };
template<int i>
class Outer {
private:
template<class T> 
static constexpr auto compute_type() {
if constexpr (i == 42) {
return TypeHolder<bool>{};
} else {
return TypeHolder<T>{};
}
}
public:
template<class T>
using TheType = typename decltype(Outer<i>::compute_type<T>())::type;
};
int main() {
Outer<42>::TheType<int> i;
}

叮当告诉我:

<source>:17:49: error: 'compute_type' is a private member of 'Outer<42>'

。当然是这样,但我正在尝试从同一类内部访问该成员。我不明白为什么它不应该在那里访问。我是否遇到(并且我应该提交(Clang错误?

你可以在Godbolt的编译器资源管理器中玩弄代码。

这是核心问题 1554。该标准不清楚如何对别名模板执行访问检查(在定义上下文中或使用上下文中(。

当前方向是在定义的上下文中进行检查,这将使您的代码格式良好。