/* The initializer must be an integer constant expression,
representable in the target type. */
if (!int_const_expr)
- error_at (loc, "%<constexpr%> integer initializer is not an "
- "integer constant expression");
+ {
+ if (TREE_CODE (init) == RAW_DATA_CST
+ && TYPE_PRECISION (type) == CHAR_BIT)
+ {
+ if (!TYPE_UNSIGNED (type))
+ for (unsigned int i = 0;
+ i < (unsigned) RAW_DATA_LENGTH (init); ++i)
+ if (RAW_DATA_SCHAR_ELT (init, i) < 0)
+ {
+ error_at (loc, "%<constexpr%> initializer not "
+ "representable in type of object");
+ break;
+ }
+ }
+ else
+ error_at (loc, "%<constexpr%> integer initializer is not an "
+ "integer constant expression");
+ }
else if (!int_fits_type_p (init, type))
error_at (loc, "%<constexpr%> initializer not representable in "
"type of object");
--- /dev/null
+/* PR c/120057 */
+/* { dg-do compile } */
+/* { dg-options "-std=c23" } */
+
+constexpr char foo[65] = {
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+ 1
+};
+constexpr char bar[66] = {
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+ 1, 2
+};
--- /dev/null
+/* PR c/120057 */
+/* { dg-do compile } */
+/* { dg-options "-std=c23" } */
+
+constexpr signed char foo[65] = {
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 129, 11, 12, 13, 14, 15, 16, /* { dg-error "'constexpr' initializer not representable in type of object" } */
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+ 1
+};