diff options
author | Joseph Myers <joseph@codesourcery.com> | 2009-04-26 00:30:10 +0100 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2009-04-26 00:30:10 +0100 |
commit | 6895bac810775d772310a2772b7eafd0ac944b5f (patch) | |
tree | 35521b0d5e431f68faee7dbbfd427e26918ae543 /gcc | |
parent | 24070fcb42eca4e9df8129f9c3ffb3cf71379fa5 (diff) | |
download | gcc-6895bac810775d772310a2772b7eafd0ac944b5f.zip gcc-6895bac810775d772310a2772b7eafd0ac944b5f.tar.gz gcc-6895bac810775d772310a2772b7eafd0ac944b5f.tar.bz2 |
c-decl.c (build_enumerator): Allow values folding to integer constants but not integer constant expressions...
* c-decl.c (build_enumerator): Allow values folding to integer
constants but not integer constant expressions with a pedwarn if
pedantic.
testsuite:
* gcc.dg/enum-const-1.c, gcc.dg/enum-const-2.c,
gcc.dg/enum-const-3.c: New tests.
* gcc.dg/gnu89-const-expr-1.c, gcc.dg/gnu99-const-expr-1.c: Use
-pedantic-errors. Update expected diagnostics.
From-SVN: r146789
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c-decl.c | 24 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/enum-const-1.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/enum-const-2.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/enum-const-3.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/gnu89-const-expr-1.c | 35 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/gnu99-const-expr-1.c | 29 |
8 files changed, 98 insertions, 27 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b454cb6..badad85 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,11 @@ 2009-04-25 Joseph Myers <joseph@codesourcery.com> + * c-decl.c (build_enumerator): Allow values folding to integer + constants but not integer constant expressions with a pedwarn if + pedantic. + +2009-04-25 Joseph Myers <joseph@codesourcery.com> + PR c/39582 * c-typeck.c (c_expr_sizeof_type): Create a C_MAYBE_CONST_EXPR with non-null C_MAYBE_CONST_EXPR_PRE if size of a variable-length diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 9693a34..7732d5a 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -6077,16 +6077,32 @@ build_enumerator (struct c_enum_contents *the_enum, tree name, tree value, undeclared identifier) - just ignore the value expression. */ if (value == error_mark_node) value = 0; - else if (!INTEGRAL_TYPE_P (TREE_TYPE (value)) - || TREE_CODE (value) != INTEGER_CST) + else if (!INTEGRAL_TYPE_P (TREE_TYPE (value))) { error ("enumerator value for %qE is not an integer constant", name); value = 0; } else { - value = default_conversion (value); - constant_expression_warning (value); + if (TREE_CODE (value) != INTEGER_CST) + { + value = c_fully_fold (value, false, NULL); + if (TREE_CODE (value) == INTEGER_CST) + pedwarn (value_loc, OPT_pedantic, + "enumerator value for %qE is not an integer " + "constant expression", name); + } + if (TREE_CODE (value) != INTEGER_CST) + { + error ("enumerator value for %qE is not an integer constant", + name); + value = 0; + } + else + { + value = default_conversion (value); + constant_expression_warning (value); + } } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 44c8c1a..36b1a49 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,12 @@ 2009-04-25 Joseph Myers <joseph@codesourcery.com> + * gcc.dg/enum-const-1.c, gcc.dg/enum-const-2.c, + gcc.dg/enum-const-3.c: New tests. + * gcc.dg/gnu89-const-expr-1.c, gcc.dg/gnu99-const-expr-1.c: Use + -pedantic-errors. Update expected diagnostics. + +2009-04-25 Joseph Myers <joseph@codesourcery.com> + PR c/39582 * gcc.dg/vla-20.c: New test. diff --git a/gcc/testsuite/gcc.dg/enum-const-1.c b/gcc/testsuite/gcc.dg/enum-const-1.c new file mode 100644 index 0000000..205bb23 --- /dev/null +++ b/gcc/testsuite/gcc.dg/enum-const-1.c @@ -0,0 +1,8 @@ +/* Test for enumeration constants not integer constant expressions but + folding to integer constants (used in Linux kernel, + <http://gcc.gnu.org/ml/gcc/2009-04/msg00677.html>). */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +extern int i; +enum e { E = (1 ? 1 : i) }; diff --git a/gcc/testsuite/gcc.dg/enum-const-2.c b/gcc/testsuite/gcc.dg/enum-const-2.c new file mode 100644 index 0000000..7e83a6f --- /dev/null +++ b/gcc/testsuite/gcc.dg/enum-const-2.c @@ -0,0 +1,8 @@ +/* Test for enumeration constants not integer constant expressions but + folding to integer constants (used in Linux kernel, + <http://gcc.gnu.org/ml/gcc/2009-04/msg00677.html>). */ +/* { dg-do compile } */ +/* { dg-options "-pedantic" } */ + +extern int i; +enum e { E = (1 ? 1 : i) }; /* { dg-warning "not an integer constant expression" } */ diff --git a/gcc/testsuite/gcc.dg/enum-const-3.c b/gcc/testsuite/gcc.dg/enum-const-3.c new file mode 100644 index 0000000..ab355ca --- /dev/null +++ b/gcc/testsuite/gcc.dg/enum-const-3.c @@ -0,0 +1,8 @@ +/* Test for enumeration constants not integer constant expressions but + folding to integer constants (used in Linux kernel, + <http://gcc.gnu.org/ml/gcc/2009-04/msg00677.html>). */ +/* { dg-do compile } */ +/* { dg-options "-pedantic-errors" } */ + +extern int i; +enum e { E = (1 ? 1 : i) }; /* { dg-error "not an integer constant expression" } */ diff --git a/gcc/testsuite/gcc.dg/gnu89-const-expr-1.c b/gcc/testsuite/gcc.dg/gnu89-const-expr-1.c index ebc6885..4fd6671 100644 --- a/gcc/testsuite/gcc.dg/gnu89-const-expr-1.c +++ b/gcc/testsuite/gcc.dg/gnu89-const-expr-1.c @@ -1,7 +1,7 @@ /* Test for constant expressions: GNU extensions. */ /* Origin: Joseph Myers <joseph@codesourcery.com> */ /* { dg-do compile } */ -/* { dg-options "-std=gnu89" } */ +/* { dg-options "-std=gnu89 -pedantic-errors" } */ int n; @@ -9,39 +9,48 @@ void f (void) { int i = 0; - int a[n]; + int a[n]; /* { dg-error "ISO C90 forbids variable length array" } */ enum e1 { /* Integer constant expressions may not contain statement expressions (not a permitted operand). */ - E1 = (1 ? 0 : ({ 0; })), /* { dg-error "constant" } */ + E1 = (1 ? 0 : ({ 0; })), /* { dg-error "constant expression" } */ + /* { dg-error "ISO C forbids braced-groups" "ISO" { target *-*-* } 16 } */ /* Real and imaginary parts act like other arithmetic operators. */ - E2 = __real__ (1 ? 0 : i++), /* { dg-error "constant" } */ + E2 = __real__ (1 ? 0 : i++), /* { dg-error "constant expression" } */ E3 = __real__ 0, E4 = __imag__ (1 ? 0 : i++), /* { dg-error "constant" } */ E5 = __imag__ 0, /* __alignof__ always constant. */ - E6 = __alignof__ (int[n]), + E6 = __alignof__ (int[n]), /* { dg-error "ISO C90 forbids variable length array" } */ E7 = __alignof__ (a), /* __extension__ ignored for constant expression purposes. */ - E8 = __extension__ (1 ? 0 : i++), /* { dg-error "constant" } */ + E8 = __extension__ (1 ? 0 : i++), /* { dg-error "constant expression" } */ E9 = __extension__ 0, /* Conditional expressions with omitted arguments act like the standard type. */ - E10 = (1 ? : i++), /* { dg-error "constant" } */ - E11 = (1 ? : 0) + E10 = (1 ? : i++), /* { dg-error "constant expression" } */ + /* { dg-error "ISO C forbids omitting" "ISO" { target *-*-* } 32 } */ + E11 = (1 ? : 0) /* { dg-error "ISO C forbids omitting" } */ }; enum e2 { /* Complex integer constants may be cast directly to integer types, but not after further arithmetic on them. */ - F1 = (int) (_Complex int) 2i, /* { dg-error "constant" } */ - F2 = (int) +2i, /* { dg-error "constant" } */ - F3 = (int) (1 + 2i), /* { dg-error "constant" } */ - F4 = (int) 2i + F1 = (int) (_Complex int) 2i, /* { dg-error "constant expression" } */ + /* { dg-error "complex" "complex" { target *-*-* } 39 } */ + /* { dg-error "imaginary" "imaginary" { target *-*-* } 39 } */ + F2 = (int) +2i, /* { dg-error "constant expression" } */ + /* { dg-error "imaginary" "ISO" { target *-*-* } 42 } */ + F3 = (int) (1 + 2i), /* { dg-error "constant expression" } */ + /* { dg-error "imaginary" "ISO" { target *-*-* } 44 } */ + F4 = (int) 2i /* { dg-error "imaginary" } */ }; static double dr = __real__ (1.0 + 2.0i); + /* { dg-error "imaginary" "ISO" { target *-*-* } 48 } */ static double di = __imag__ (1.0 + 2.0i); + /* { dg-error "imaginary" "ISO" { target *-*-* } 50 } */ /* Statement expressions allowed in unevaluated subexpressions in initializers in gnu99 but not gnu89. */ - static int j = (1 ? 0 : ({ 0; })); /* { dg-warning "constant expression" } */ + static int j = (1 ? 0 : ({ 0; })); /* { dg-error "constant expression" } */ + /* { dg-error "braced" "ISO" { target *-*-* } 54 } */ } diff --git a/gcc/testsuite/gcc.dg/gnu99-const-expr-1.c b/gcc/testsuite/gcc.dg/gnu99-const-expr-1.c index dcc976e..3f5f25e 100644 --- a/gcc/testsuite/gcc.dg/gnu99-const-expr-1.c +++ b/gcc/testsuite/gcc.dg/gnu99-const-expr-1.c @@ -1,7 +1,7 @@ /* Test for constant expressions: GNU extensions. */ /* Origin: Joseph Myers <joseph@codesourcery.com> */ /* { dg-do compile } */ -/* { dg-options "-std=gnu99" } */ +/* { dg-options "-std=gnu99 -pedantic-errors" } */ int n; @@ -13,10 +13,11 @@ f (void) enum e1 { /* Integer constant expressions may not contain statement expressions (not a permitted operand). */ - E1 = (1 ? 0 : ({ 0; })), /* { dg-error "constant" } */ + E1 = (1 ? 0 : ({ 0; })), /* { dg-error "constant expression" } */ + /* { dg-error "ISO C forbids braced-groups" "ISO" { target *-*-* } 16 } */ /* Real and imaginary parts act like other arithmetic operators. */ - E2 = __real__ (1 ? 0 : i++), /* { dg-error "constant" } */ + E2 = __real__ (1 ? 0 : i++), /* { dg-error "constant expression" } */ E3 = __real__ 0, E4 = __imag__ (1 ? 0 : i++), /* { dg-error "constant" } */ E5 = __imag__ 0, @@ -24,24 +25,32 @@ f (void) E6 = __alignof__ (int[n]), E7 = __alignof__ (a), /* __extension__ ignored for constant expression purposes. */ - E8 = __extension__ (1 ? 0 : i++), /* { dg-error "constant" } */ + E8 = __extension__ (1 ? 0 : i++), /* { dg-error "constant expression" } */ E9 = __extension__ 0, /* Conditional expressions with omitted arguments act like the standard type. */ - E10 = (1 ? : i++), /* { dg-error "constant" } */ - E11 = (1 ? : 0) + E10 = (1 ? : i++), /* { dg-error "constant expression" } */ + /* { dg-error "ISO C forbids omitting" "ISO" { target *-*-* } 32 } */ + E11 = (1 ? : 0) /* { dg-error "ISO C forbids omitting" } */ }; enum e2 { /* Complex integer constants may be cast directly to integer types, but not after further arithmetic on them. */ - F1 = (int) (_Complex int) 2i, /* { dg-error "constant" } */ - F2 = (int) +2i, /* { dg-error "constant" } */ - F3 = (int) (1 + 2i), /* { dg-error "constant" } */ - F4 = (int) 2i + F1 = (int) (_Complex int) 2i, /* { dg-error "constant expression" } */ + /* { dg-error "complex" "complex" { target *-*-* } 39 } */ + /* { dg-error "imaginary" "imaginary" { target *-*-* } 39 } */ + F2 = (int) +2i, /* { dg-error "constant expression" } */ + /* { dg-error "imaginary" "ISO" { target *-*-* } 42 } */ + F3 = (int) (1 + 2i), /* { dg-error "constant expression" } */ + /* { dg-error "imaginary" "ISO" { target *-*-* } 44 } */ + F4 = (int) 2i /* { dg-error "imaginary" } */ }; static double dr = __real__ (1.0 + 2.0i); + /* { dg-error "imaginary" "ISO" { target *-*-* } 48 } */ static double di = __imag__ (1.0 + 2.0i); + /* { dg-error "imaginary" "ISO" { target *-*-* } 50 } */ /* Statement expressions allowed in unevaluated subexpressions in initializers in gnu99 but not gnu89. */ static int j = (1 ? 0 : ({ 0; })); + /* { dg-error "braced" "ISO" { target *-*-* } 54 } */ } |