https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121521
Bug ID: 121521 Summary: elements of std::array in constexpr structured binding is not a constant expression Product: gcc Version: 16.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: cooky.ykooc922 at gmail dot com Target Milestone: --- #include <array> struct Point { int x, y, z; }; int main() { constexpr int arr[] {1, 2, 3}; constexpr auto [a, b, c] = arr; constexpr std::array std_arr {4, 5, 6}; constexpr auto [d, e, f] = std_arr; // error constexpr auto [g, h, i] = std::array{42, 91, 72}; // error constexpr auto [x, y, z] = Point {9, 0, -4}; } >From the snippet of code above, constexpr structured bindings have no problems with native arrays and aggregate types. But with std::array (has a member array and uses the tuple protocol), the compiler rejects two lines: <source>:12:32: error: '<structured bindings>.std::array<int, 3>::_M_elems[0]' is not a constant expression 12 | constexpr auto [d, e, f] = std_arr; // error | ^~~~~~~ <source>:12:32: error: '<structured bindings>.std::array<int, 3>::_M_elems[1]' is not a constant expression <source>:12:32: error: '<structured bindings>.std::array<int, 3>::_M_elems[2]' is not a constant expression <source>:13:53: error: '<structured bindings>.std::array<int, 3>::_M_elems[0]' is not a constant expression 13 | constexpr auto [g, h, i] = std::array{42, 91, 72}; // error | ^ <source>:13:53: error: '<structured bindings>.std::array<int, 3>::_M_elems[1]' is not a constant expression <source>:13:53: error: '<structured bindings>.std::array<int, 3>::_M_elems[2]' is not a constant expression