#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
Edited testcase: #include <array> #include <tuple> struct Point { int x, y, z; }; int main() { constexpr int arr[] {1, 2, 3}; constexpr auto [a, b, c] = arr; static 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 [j, k] = std::make_tuple(1, 3.14f); // error constexpr auto [l, m] = std::pair {'A', true}; // error constexpr auto [x, y, z] = Point {9, 0, -4}; } In general, it rejects lines that accept objects of types with tuple protocol.
https://gcc.gnu.org/projects/cxx-status.html#cxx26 clearly states that the whole paper has not been implemented yet, only the smaller part of it which allows constexpr and constinit keyword on structured bindings. So, in some cases for now the structured binding needs to be static if it needs to be constexpr, because the references to constexpr vars part of the paper is not implemented yet. PR117784 says that too. *** This bug has been marked as a duplicate of bug 117784 ***