类无法访问自己的私有静态 constexpr 方法 - Clang bug?
Class can't access its own private static constexpr method - Clang bug?
这段代码不能在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。该标准不清楚如何对别名模板执行访问检查(在定义上下文中或使用上下文中(。
当前方向是在定义的上下文中进行检查,这将使您的代码格式良好。
相关文章:
- 类无法访问自己的私有静态 constexpr 方法 - Clang bug?
- 从非类型模板参数声明 constexpr 数组的可移植方法
- 调用模板参数 constexpr 方法?
- MSVC使用constexpr-if从可变模板方法中的基本模板参数中吞下const
- 强制 constexpr 函数的 constexpr 的惯用方法
- 用霍纳方法进行多项式求值的C++ constexpr
- 为什么 constexpr 假设我的方法就是 const
- 是否有一种方法可以避免标头文件中使用的constexpr函数输入全局范围,而无需额外的名称空间
- 使用方法失败更改constexpr对象成员
- 当应用于静态方法时,为什么constexpr属性不起作用
- 如何在 C++11 中编写这个 C++17 静态 constexpr 方法
- 只要调用的函数是用constexpr指定的,就将委托方法声明为constexpr
- 使用constexpr方法在结构内部进行模板参数化
- 带字符串操作变通方法的constexpr
- 是否有模板/constexpr/ c++ 11替代x -宏的方法?
- Constexpr类与数组构造函数方法
- 静态constexpr方法实现导致GCC错误
- 在c++ 11或更高版本中,是否有一种方法可以让constexpr在没有UB的情况下确定endian ?
- 声明constexpr函数或方法
- 在C++11中计算编译时的斐波那契数(递归方法)(constexpr)