@@ -974,6 +974,12 @@ check_global_declaration (symtab_node *snode)
? OPT_Wunused_const_variable
: OPT_Wunused_variable),
"%qD defined but not used", decl);
+
+ if (VAR_P (decl) && !DECL_EXTERNAL (decl)
+ && RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl)) && DECL_SIZE (decl) == 0)
+ {
+ error ("storage size of %q+D isn%'t known", decl);
+ }
}
/* Discover all functions and variables that are trivially needed, analyze
@@ -33,6 +33,7 @@ enum e3
__typeof__ (struct s5 { int i; }) v5; /* { dg-warning "invalid in C\[+\]\[+\]" } */
__typeof__ (struct t5) w5; /* { dg-bogus "invalid in C\[+\]\[+\]" } */
+ /* { dg-error "storage size of 'w5' isn't known" "" { target *-*-* } 35 } */
int
f1 (struct s1 *p)
@@ -64,4 +65,4 @@ f5 ()
return &((struct t8) { }); /* { dg-warning "invalid in C\[+\]\[+\]" } */
}
-/* { dg-error "invalid use of undefined type" "" { target *-*-* } 64 } */
+/* { dg-error "invalid use of undefined type" "" { target *-*-* } 65 } */
@@ -9,7 +9,8 @@ typedef int t;
/* These should all be diagnosed, but only once, not for every
identifier declared. */
struct s0 int x0, /* { dg-error "two or more data types" } */
-x1;
+/* { dg-error "storage size of 'x0' isn't known" "" { target *-*-* } 11 } */
+x1; /* { dg-error "storage size of 'x1' isn't known" } */
char union u0 x2, /* { dg-error "two or more data types" } */
x3;
new file mode 100644
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+static struct foo x; /* { dg-error "storage size of 'x' isn't known" } */
+static union bar y; /* { dg-error "storage size of 'y' isn't known" } */
+
+typedef struct P p;
+static p p_obj; /* { dg-error "storage size of 'p_obj' isn't known" } */
+
+extern struct undefined_object object;