diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a99197af5a1..b01a75ae917 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2007-09-25 Joseph Myers + + PR c/32295 + * c-typeck.c (default_conversion): Call require_complete_type + before perform_integral_promotions. + (build_unary_op): Call require_complete_type except for ADDR_EXPR. + (build_c_cast): Call require_complete_type except for casts to + void types. + (convert_for_assignment): Call require_complete_type. + 2007-09-25 Revital Eres * config/spu/spu.md: Fix doloop pattern. diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index a9220810c2f..0bad8e5a45c 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -1770,14 +1770,19 @@ default_conversion (tree exp) if (TREE_NO_WARNING (orig_exp)) TREE_NO_WARNING (exp) = 1; - if (INTEGRAL_TYPE_P (type)) - return perform_integral_promotions (exp); - if (code == VOID_TYPE) { error ("void value not ignored as it ought to be"); return error_mark_node; } + + exp = require_complete_type (exp); + if (exp == error_mark_node) + return error_mark_node; + + if (INTEGRAL_TYPE_P (type)) + return perform_integral_promotions (exp); + return exp; } @@ -2871,11 +2876,15 @@ build_unary_op (enum tree_code code, tree xarg, int flag) /* No default_conversion here. It causes trouble for ADDR_EXPR. */ tree arg = xarg; tree argtype = 0; - enum tree_code typecode = TREE_CODE (TREE_TYPE (arg)); + enum tree_code typecode; tree val; int noconvert = flag; const char *invalid_op_diag; + if (code != ADDR_EXPR) + arg = require_complete_type (arg); + + typecode = TREE_CODE (TREE_TYPE (arg)); if (typecode == ERROR_MARK) return error_mark_node; if (typecode == ENUMERAL_TYPE || typecode == BOOLEAN_TYPE) @@ -3589,6 +3598,13 @@ build_c_cast (tree type, tree expr) return error_mark_node; } + if (!VOID_TYPE_P (type)) + { + value = require_complete_type (value); + if (value == error_mark_node) + return error_mark_node; + } + if (type == TYPE_MAIN_VARIANT (TREE_TYPE (value))) { if (pedantic) @@ -3998,6 +4014,9 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype, error ("void value not ignored as it ought to be"); return error_mark_node; } + rhs = require_complete_type (rhs); + if (rhs == error_mark_node) + return error_mark_node; /* A type converts to a reference to it. This code doesn't fully support references, it's just for the special case of va_start and va_copy. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5d7a0f86b9c..4f8d576c4d1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-09-25 Joseph Myers + + PR c/32295 + * gcc.dg/enum-incomplete-1.c: New test. + 2007-09-25 Bernd Schmidt * gcc.c-torture/compile/20070919-1.c: New test. diff --git a/gcc/testsuite/gcc.dg/enum-incomplete-1.c b/gcc/testsuite/gcc.dg/enum-incomplete-1.c new file mode 100644 index 00000000000..06c247c2e51 --- /dev/null +++ b/gcc/testsuite/gcc.dg/enum-incomplete-1.c @@ -0,0 +1,86 @@ +/* Test for uses of incomplete enum variables: should be allowed just + when incomplete structs are allowed. PR 32295. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +extern enum e ve; +extern struct s vs; +void *p; + +int +f0 (int i) +{ + ve; /* { dg-error "incomplete" } */ + vs; /* { dg-error "incomplete" } */ + (void) ve; + (void) vs; + (void) (i ? ve : ve); /* { dg-error "incomplete" } */ + (void) (i ? vs : vs); /* { dg-error "incomplete" } */ + (void) (ve = ve); /* { dg-error "incomplete" } */ + (void) (vs = vs); /* { dg-error "incomplete" } */ + (void) ve, (void) ve; + (void) vs, (void) vs; + p = &ve; + p = &vs; + (void) sizeof (ve); /* { dg-error "incomplete" } */ + (void) sizeof (vs); /* { dg-error "incomplete" } */ + typeof (ve) *pe; + typeof (vs) *ps; + /* ??? alignof should probably not be accepted here. */ + (void) __alignof (ve); + (void) __alignof (vs); + (void) (ve + i); /* { dg-error "incomplete" } */ + (void) (i * ve); /* { dg-error "incomplete" } */ + (void) (i / ve); /* { dg-error "incomplete" } */ + (void) (ve - i); /* { dg-error "incomplete" } */ + (void) (ve << i); /* { dg-error "incomplete" } */ + (void) (i >> ve); /* { dg-error "incomplete" } */ + (void) (ve < i); /* { dg-error "incomplete" } */ + (void) (ve <= i); /* { dg-error "incomplete" } */ + (void) (i > ve); /* { dg-error "incomplete" } */ + (void) (i >= ve); /* { dg-error "incomplete" } */ + (void) (ve == i); /* { dg-error "incomplete" } */ + (void) (i != ve); /* { dg-error "incomplete" } */ + (void) (ve & i); /* { dg-error "incomplete" } */ + (void) (ve ^ i); /* { dg-error "incomplete" } */ + (void) (i | ve); /* { dg-error "incomplete" } */ + (void) (i && ve); /* { dg-error "incomplete" } */ + (void) (ve || i); /* { dg-error "incomplete" } */ + (void) -ve; /* { dg-error "incomplete" } */ + (void) +ve; /* { dg-error "incomplete" } */ + (void) ~ve; /* { dg-error "incomplete" } */ + (void) !ve; /* { dg-error "incomplete" } */ + (void) --ve; /* { dg-error "incomplete" } */ + (void) ++ve; /* { dg-error "incomplete" } */ + (void) ve--; /* { dg-error "incomplete" } */ + (void) ve++; /* { dg-error "incomplete" } */ + i = ve; /* { dg-error "incomplete" } */ + i *= ve; /* { dg-error "incomplete" } */ + i /= ve; /* { dg-error "incomplete" } */ + i %= ve; /* { dg-error "incomplete" } */ + i += ve; /* { dg-error "incomplete" } */ + i -= ve; /* { dg-error "incomplete" } */ + i <<= ve; /* { dg-error "incomplete" } */ + i >>= ve; /* { dg-error "incomplete" } */ + i &= ve; /* { dg-error "incomplete" } */ + i ^= ve; /* { dg-error "incomplete" } */ + i |= ve; /* { dg-error "incomplete" } */ + (void) (ve ? 1 : 1); /* { dg-error "incomplete" } */ + (void) (int) ve; /* { dg-error "incomplete" } */ + f0 (ve); /* { dg-error "incomplete" } */ + if (ve) /* { dg-error "incomplete" } */ + ; + do + ; + while (ve); /* { dg-error "incomplete" } */ + while (ve) /* { dg-error "incomplete" } */ + ; + _Bool b = ve; /* { dg-error "incomplete" } */ + float f = ve; /* { dg-error "incomplete" } */ + switch (ve) /* { dg-error "incomplete" } */ + ; + for (; ve;) /* { dg-error "incomplete" } */ + ; + return ve; /* { dg-error "incomplete" } */ +}