为什么这个constexpr static由//! Nah注释标识的成员函数constexpr在调用时看不到?
struct Item_id
{
enum Enum
{
size, position, attributes, window_rect, max_window_size, _
};
static constexpr int n_items_ = _; // OK
constexpr auto member_n_items() const -> int { return _; } // OK
static constexpr auto static_n_items() -> int { return _; } // OK
static constexpr int so_far = n_items_; // OK
#ifndef OUT_OF_CLASS
static constexpr int bah = static_n_items(); //! Nah.
#endif
};
constexpr auto n_ids() -> int { …Run Code Online (Sandbox Code Playgroud) 我使用的是g ++ 4.8.0,它不包含早期的constexprbug.因此下面的代码工作正常:
constexpr int size() { return 5; }
int array[size()];
int main () {}
Run Code Online (Sandbox Code Playgroud)
但是,如果我将变量括在一个classas中static,那么它会给出编译器错误:
struct X {
constexpr static int size() { return 5; }
static const int array[size()];
};
int main () {}
Run Code Online (Sandbox Code Playgroud)
这是错误:
错误:数组'array'的大小不是整数常量表达式
禁止以constexpr这种方式使用还是使用另一个g ++ bug?