&& !DECL_EXTERNAL (decl)
&& TYPE_DOMAIN (type) == NULL_TREE)
{
- warning_at (DECL_SOURCE_LOCATION (decl),
- 0, "array %q+D assumed to have one element", decl);
+ if (flag_isoc2y && !TREE_PUBLIC (decl))
+ error_at (DECL_SOURCE_LOCATION (decl),
+ "array size missing in %q+D", decl);
+ else
+ warning_at (DECL_SOURCE_LOCATION (decl),
+ 0, "array %q+D assumed to have one element", decl);
complete_array_type (&TREE_TYPE (decl), NULL_TREE, true);
&& !(TREE_PUBLIC (decl) && current_scope != file_scope))
{
bool do_default
- = (TREE_STATIC (decl)
- /* Even if pedantic, an external linkage array
- may have incomplete type at first. */
- ? pedantic && !TREE_PUBLIC (decl)
- : !DECL_EXTERNAL (decl));
+ = !TREE_STATIC (decl) && !DECL_EXTERNAL (decl);
int failure
= complete_array_type (&TREE_TYPE (decl), DECL_INITIAL (decl),
do_default);
case 2:
if (do_default)
error ("array size missing in %q+D", decl);
+ else if (!TREE_PUBLIC (decl))
+ pedwarn_c23 (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
+ "array size missing in %q+D", decl);
break;
case 3:
--- /dev/null
+/* Test tentative definitions with incomplete type: OK in C2y with internal
+ linkage if completed by the end of the translation unit, but not allowed in
+ C23. Note that incomplete structs and unions are not diagnosed for C23 when
+ completed by the end of the translation unit (bug 88727). */
+/* { dg-do compile } */
+/* { dg-options "-std=c23 -pedantic-errors" } */
+
+struct s1;
+struct s2;
+union u1;
+union u2;
+
+struct s1 v1;
+struct s2 v2; /* { dg-error "storage size" } */
+int v3[];
+int v4[]; /* { dg-warning "assumed to have one element" } */
+union u1 v5;
+union u2 v6; /* { dg-error "storage size" } */
+
+static struct s1 sv1;
+static struct s2 sv2; /* { dg-error "storage size" } */
+static int sv3[]; /* { dg-error "array size missing" } */
+static int sv4[]; /* { dg-error "array size missing" } */
+/* { dg-warning "assumed to have one element" "one element" { target *-*-* } .-1 } */
+static union u1 sv5;
+static union u2 sv6; /* { dg-error "storage size" } */
+
+struct s1 { int x; };
+union u1 { int y; };
+extern int v3[1];
+extern int sv3[1];
--- /dev/null
+/* Test tentative definitions with incomplete type: OK in C2y with internal
+ linkage if completed by the end of the translation unit, but not allowed in
+ C23. Note that incomplete structs and unions are not diagnosed for C23 when
+ completed by the end of the translation unit (bug 88727). */
+/* { dg-do compile } */
+/* { dg-options "-std=c23 -pedantic" } */
+
+struct s1;
+struct s2;
+union u1;
+union u2;
+
+struct s1 v1;
+struct s2 v2; /* { dg-error "storage size" } */
+int v3[];
+int v4[]; /* { dg-warning "assumed to have one element" } */
+union u1 v5;
+union u2 v6; /* { dg-error "storage size" } */
+
+static struct s1 sv1;
+static struct s2 sv2; /* { dg-error "storage size" } */
+static int sv3[]; /* { dg-warning "array size missing" } */
+static int sv4[]; /* { dg-warning "array size missing" } */
+/* { dg-warning "assumed to have one element" "one element" { target *-*-* } .-1 } */
+static union u1 sv5;
+static union u2 sv6; /* { dg-error "storage size" } */
+
+struct s1 { int x; };
+union u1 { int y; };
+extern int v3[1];
+extern int sv3[1];
--- /dev/null
+/* Test tentative definitions with incomplete type: OK in C2y with internal
+ linkage if completed by the end of the translation unit, but not allowed in
+ C23. Note that incomplete structs and unions are not diagnosed for C23 when
+ completed by the end of the translation unit (bug 88727). */
+/* { dg-do compile } */
+/* { dg-options "-std=c23 -pedantic-errors -Wno-c23-c2y-compat" } */
+
+struct s1;
+struct s2;
+union u1;
+union u2;
+
+struct s1 v1;
+struct s2 v2; /* { dg-error "storage size" } */
+int v3[];
+int v4[]; /* { dg-warning "assumed to have one element" } */
+union u1 v5;
+union u2 v6; /* { dg-error "storage size" } */
+
+static struct s1 sv1;
+static struct s2 sv2; /* { dg-error "storage size" } */
+static int sv3[];
+static int sv4[]; /* { dg-warning "assumed to have one element" } */
+static union u1 sv5;
+static union u2 sv6; /* { dg-error "storage size" } */
+
+struct s1 { int x; };
+union u1 { int y; };
+extern int v3[1];
+extern int sv3[1];
rather than defaulting to size 1. */
thread_local int g[]; /* { dg-error "storage size" } */
static thread_local int h[]; /* { dg-error "array size missing" } */
+/* { dg-error "storage size" "storage size" { target *-*-* } .-1 } */
extern thread_local int i[];
thread_local int j[] = { 0 };
struct s1 a; /* { dg-error "storage size" } */
int b[]; /* { dg-error "array size missing" } */
static struct s1 c; /* { dg-error "storage size" } */
- static int d[]; /* { dg-error "array size missing" } */
+ static int d[]; /* { dg-error "storage size" } */
struct s2;
struct s2 e; /* { dg-error "storage size" } */
static struct s2 g; /* { dg-error "storage size" } */
--- /dev/null
+/* Test tentative definitions with incomplete type: OK in C2y with internal
+ linkage if completed by the end of the translation unit. */
+/* { dg-do compile } */
+/* { dg-options "-std=c2y -pedantic-errors" } */
+
+struct s1;
+struct s2;
+union u1;
+union u2;
+
+struct s1 v1;
+struct s2 v2; /* { dg-error "storage size" } */
+int v3[];
+int v4[]; /* { dg-warning "assumed to have one element" } */
+union u1 v5;
+union u2 v6; /* { dg-error "storage size" } */
+
+static struct s1 sv1;
+static struct s2 sv2; /* { dg-error "storage size" } */
+static int sv3[];
+static int sv4[]; /* { dg-error "array size missing" } */
+static union u1 sv5;
+static union u2 sv6; /* { dg-error "storage size" } */
+
+struct s1 { int x; };
+union u1 { int y; };
+extern int v3[1];
+extern int sv3[1];
--- /dev/null
+/* Test tentative definitions with incomplete type: OK in C2y with internal
+ linkage if completed by the end of the translation unit. */
+/* { dg-do compile } */
+/* { dg-options "-std=c2y -pedantic-errors -Wc23-c2y-compat" } */
+
+struct s1;
+struct s2;
+union u1;
+union u2;
+
+struct s1 v1;
+struct s2 v2; /* { dg-error "storage size" } */
+int v3[];
+int v4[]; /* { dg-warning "assumed to have one element" } */
+union u1 v5;
+union u2 v6; /* { dg-error "storage size" } */
+
+static struct s1 sv1;
+static struct s2 sv2; /* { dg-error "storage size" } */
+static int sv3[]; /* { dg-warning "array size missing" } */
+static int sv4[]; /* { dg-error "array size missing" } */
+/* { dg-warning "array size missing" "warning" { target *-*-* } .-1 } */
+static union u1 sv5;
+static union u2 sv6; /* { dg-error "storage size" } */
+
+struct s1 { int x; };
+union u1 { int y; };
+extern int v3[1];
+extern int sv3[1];