Why is std::array::size constexpr with simple types (int, double, …) but not std::vector (GCC)?

前端 未结 1 726
轮回少年
轮回少年 2021-01-04 01:56

The following code:

std::array arr1;
std::array arr2;

...compiles with both gcc and

相关标签:
1条回答
  • 2021-01-04 02:19

    I think this is a related to CWG issue 1684. Previously, the constexpr requirements included:

    The class of which a constexpr function is a member shall be a literal type

    And std::array<std::vector<int>, 4> is not a literal type, and hence its size() member function would not be constexpr. However, the new wording allows for a constexpr non-static member functions for non-literal types, assuming those functions meet all the other requirements of constexpr (which array<T,N>::size() clearly does).

    Per the new wording, this is a gcc bug. Previously filed as 66297.

    0 讨论(0)
提交回复
热议问题