diff options
author | Joseph Myers <jsm@polyomino.org.uk> | 2004-01-07 22:24:44 +0000 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2004-01-07 22:24:44 +0000 |
commit | bca63328817fdf5c02d50ce227de4ef2f1c5dbdf (patch) | |
tree | 758366d4443ad9fd7fd7a5e37a42e69d047dd67a | |
parent | 158960ba7e2e8f5d4ad01e4ceb736bbbfd600e0e (diff) | |
download | gcc-bca63328817fdf5c02d50ce227de4ef2f1c5dbdf.zip gcc-bca63328817fdf5c02d50ce227de4ef2f1c5dbdf.tar.gz gcc-bca63328817fdf5c02d50ce227de4ef2f1c5dbdf.tar.bz2 |
re PR c/6024 (GCC fails to diagnose mismatch of enum types in prototype/function)
PR c/6024
* c-typeck.c (comptypes): Only treat enumerated types in the same
translation unit as compatible with each other when they are the
same type.
* doc/extend.texi: Update.
f:
* com.h (ffecom_gfrt_basictype): Correct return type.
testsuite:
* gcc.dg/enum-compat-1.c: New test.
* gcc.c-torture/execute/builtin-types-compatible-p.c: Update.
From-SVN: r75521
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/c-typeck.c | 9 | ||||
-rw-r--r-- | gcc/doc/extend.texi | 6 | ||||
-rw-r--r-- | gcc/f/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/f/com.h | 4 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/execute/builtin-types-compatible-p.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/enum-compat-1.c | 32 |
8 files changed, 62 insertions, 9 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c998446..9ceffd9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,13 @@ 2004-01-07 Joseph S. Myers <jsm@polyomino.org.uk> + PR c/6024 + * c-typeck.c (comptypes): Only treat enumerated types in the same + translation unit as compatible with each other when they are the + same type. + * doc/extend.texi: Update. + +2004-01-07 Joseph S. Myers <jsm@polyomino.org.uk> + PR c/12165 * c-decl.c (grokdeclarator): Take type qualifiers of typedefed array type from the array element type. diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index d3bf813..6d18f7e 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -474,12 +474,13 @@ comptypes (tree type1, tree type2, int flags) && TYPE_DOMAIN (t2) != 0) t2 = TYPE_DOMAIN (t2); - /* Treat an enum type as the integer type of the same width and - signedness. */ + /* Enumerated types are compatible with integer types, but this is + not transitive: two enumerated types in the same translation unit + are compatible with each other only if they are the same type. */ - if (TREE_CODE (t1) == ENUMERAL_TYPE) + if (TREE_CODE (t1) == ENUMERAL_TYPE && TREE_CODE (t2) != ENUMERAL_TYPE) t1 = c_common_type_for_size (TYPE_PRECISION (t1), TREE_UNSIGNED (t1)); - if (TREE_CODE (t2) == ENUMERAL_TYPE) + else if (TREE_CODE (t2) == ENUMERAL_TYPE && TREE_CODE (t1) != ENUMERAL_TYPE) t2 = c_common_type_for_size (TYPE_PRECISION (t2), TREE_UNSIGNED (t2)); if (t1 == t2) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index abd8415..e0361df 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -5265,8 +5265,10 @@ similarity. Consequently, @code{short *} is not similar to @code{short **}. Furthermore, two types that are typedefed are considered compatible if their underlying types are compatible. -An @code{enum} type is considered to be compatible with another -@code{enum} type. For example, @code{enum @{foo, bar@}} is similar to +An @code{enum} type is not considered to be compatible with another +@code{enum} type even if both are compatible with the same integer +type; this is what the C standard specifies. +For example, @code{enum @{foo, bar@}} is not similar to @code{enum @{hot, dog@}}. You would typically use this function in code whose execution varies diff --git a/gcc/f/ChangeLog b/gcc/f/ChangeLog index 3dcc5628..4ea7b86 100644 --- a/gcc/f/ChangeLog +++ b/gcc/f/ChangeLog @@ -1,3 +1,7 @@ +2004-01-07 Joseph S. Myers <jsm@polyomino.org.uk> + + * com.h (ffecom_gfrt_basictype): Correct return type. + 2003-12-29 Roger Sayle <roger@eyesopen.com> PR fortran/12632 diff --git a/gcc/f/com.h b/gcc/f/com.h index 4a120af..d23db66 100644 --- a/gcc/f/com.h +++ b/gcc/f/com.h @@ -1,5 +1,5 @@ /* com.h -- Public #include File (module.h template V1.0) - Copyright (C) 1995, 1996, 1997, 2000, 2003 + Copyright (C) 1995, 1996, 1997, 2000, 2003, 2004 Free Software Foundation, Inc. Contributed by James Craig Burley. @@ -228,7 +228,7 @@ void ffecom_finish_decl (tree decl, tree init, bool is_top_level); void ffecom_finish_progunit (void); tree ffecom_get_invented_identifier (const char *pattern, ...) ATTRIBUTE_PRINTF_1; -ffeinfoKindtype ffecom_gfrt_basictype (ffecomGfrt ix); +ffeinfoBasictype ffecom_gfrt_basictype (ffecomGfrt ix); ffeinfoKindtype ffecom_gfrt_kindtype (ffecomGfrt ix); void ffecom_init_0 (void); void ffecom_init_2 (void); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 020ffd8..a57afff 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,11 @@ 2004-01-07 Joseph S. Myers <jsm@polyomino.org.uk> + PR c/6024 + * gcc.dg/enum-compat-1.c: New test. + * gcc.c-torture/execute/builtin-types-compatible-p.c: Update. + +2004-01-07 Joseph S. Myers <jsm@polyomino.org.uk> + PR c/12165 * gcc.dg/array-quals-1.c, gcc.dg/c90-idem-qual-3.c, gcc.dg/c99-idem-qual-3.c: New tests. diff --git a/gcc/testsuite/gcc.c-torture/execute/builtin-types-compatible-p.c b/gcc/testsuite/gcc.c-torture/execute/builtin-types-compatible-p.c index a901c72..a998ef7 100644 --- a/gcc/testsuite/gcc.c-torture/execute/builtin-types-compatible-p.c +++ b/gcc/testsuite/gcc.c-torture/execute/builtin-types-compatible-p.c @@ -19,7 +19,6 @@ int main (void) && __builtin_types_compatible_p (typeof (hot), int) && __builtin_types_compatible_p (typeof (hot), typeof (laura)) && __builtin_types_compatible_p (int[5], int[]) - && __builtin_types_compatible_p (typeof (dingos), typeof (cranberry)) && __builtin_types_compatible_p (same1, same2))) abort (); @@ -28,6 +27,7 @@ int main (void) || __builtin_types_compatible_p (char *, const char *) || __builtin_types_compatible_p (long double, double) || __builtin_types_compatible_p (typeof (i), typeof (d)) + || __builtin_types_compatible_p (typeof (dingos), typeof (cranberry)) || __builtin_types_compatible_p (char, int) || __builtin_types_compatible_p (char *, char **)) abort (); diff --git a/gcc/testsuite/gcc.dg/enum-compat-1.c b/gcc/testsuite/gcc.dg/enum-compat-1.c new file mode 100644 index 0000000..04a6e75 --- /dev/null +++ b/gcc/testsuite/gcc.dg/enum-compat-1.c @@ -0,0 +1,32 @@ +/* Test that enumerated types are only considered compatible when they + are the same type. PR c/6024. */ +/* Origin: Joseph Myers <jsm@polyomino.org.uk>, based on + PR c/6024 from Richard Earnshaw <rearnsha@arm.com> */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +/* Original test from PR c/6024. */ +enum e1 {a, b}; +enum e2 {c, d}; + +void f(enum e1); /* { dg-error "prototype" "error at decl" } */ + +void f(x) + enum e2 x; +{ /* { dg-error "doesn't match prototype" "error at defn" } */ + return; +} + +/* Other compatibility tests. */ +enum e3 { A }; +enum e4 { B }; + +enum e3 v3; +enum e4 *p = &v3; /* { dg-warning "incompatible" "incompatible pointer" } */ +enum e3 *q = &v3; + +void g(enum e3); /* { dg-error "declaration" "error at first decl" } */ +void g(enum e4); /* { dg-error "conflicting types" "error at second decl" } */ + +void h(enum e3); +void h(enum e3); |