std::array couldn't be auto initialized for a certain data list:
static constexpr auto k_strap4_function_setting = std::array{0xf0000000, 0x70000000}; // compile error
static constexpr auto k_strap4_function_setting = std::array{0xe0000000, 0x70000000}; // compile error
static constexpr auto k_strap4_function_setting = std::array{0xd0000000, 0x70000000}; // compile error
static constexpr auto k_strap4_function_setting = std::array{0xc0000000, 0x70000000}; // compile error
static constexpr auto k_strap4_function_setting = std::array{0xb0000000, 0x70000000}; // compile error
static constexpr auto k_strap4_function_setting = std::array{0xa0000000, 0x70000000}; // compile error
static constexpr auto k_strap4_function_setting = std::array{0x90000000, 0x70000000}; // compile error
static constexpr auto k_strap4_function_setting = std::array{0x80000000, 0x70000000}; // compile error
static constexpr auto k_strap4_function_setting = std::array{0x70000000, 0x70000000}; // good to work
static constexpr auto k_strap4_function_setting = std::array{0x60000000, 0x70000000}; // good to work
static constexpr auto k_strap4_function_setting = std::array{0x50000000, 0x70000000}; // good to work
static constexpr auto k_strap4_function_setting = std::array{0x40000000, 0x70000000}; // good to work
here is the error log:
error: no viable constructor or deduction guide for deduction of template arguments of 'array'
static constexpr auto k_strap4_function_setting = std::array{0xf0000000, 0x70000000};
The only difference is the highest bit is "1" for the "compile error" define.
Does that error make sense?
Or is a bug for std::array.
The type of a hexadecimal integer literal without any suffix is the first out of the following list that is able to represent the exact value of the literal:
On a system with 32 bit wide
int, the largest value representable byintis0x7fffffffand the largest value representable byunsigned intis0xffffffff. So all literals up to0x7fffffffhave typeintand those from0x80000000to0xffffffffhave typeunsigned int.The deduction guide for
std::arrayis specified in such a way that it will fail if not all elements of the initializer have the same type. And that is why some of your examples fail.Either specify the element type of the array explicitly, e.g.
std::array<unsigned int>instead ofstd::array, so that initializers with other types will be implicitly converted to the specified element type, or addU(oru) suffixes to your literals to force them always to choose only unsigned types from the list above.