c-typeck.c (convert_arguments): When comparing for enumeral type equality, use TYPE_M...
authorNeil Booth <neil@daikokuya.demon.co.uk>
Fri, 26 Oct 2001 20:49:48 +0000 (20:49 +0000)
committerNeil Booth <neil@gcc.gnu.org>
Fri, 26 Oct 2001 20:49:48 +0000 (20:49 +0000)
* c-typeck.c (convert_arguments): When comparing for enumeral
type equality, use TYPE_MAIN_VARIANT.
* gcc.dg/Wconversion.c: New tests.

From-SVN: r46559

gcc/ChangeLog
gcc/c-typeck.c
gcc/testsuite/gcc.dg/Wconversion.c [new file with mode: 0644]

index 3fa707717110af548df79de57f55f9e07456078e..6e4d58dfe4b44343f49d5819a9082852662759fb 100644 (file)
@@ -1,3 +1,9 @@
+2001-10-26  Neil Booth  <neil@daikokuya.demon.co.uk>
+
+       * c-typeck.c (convert_arguments): When comparing for enumeral
+       type equality, use TYPE_MAIN_VARIANT.
+       * gcc.dg/Wconversion.c: New tests.
+
 2001-10-26  Kazu Hirata  <kazu@hxi.com>
 
        * s390/s390.c: Fix comment typos.
index aa7e89f7f2a14c343bba86d88cad07f72cf47966..62e7898d9a1122b21782fa1e31a3c400d34721ec 100644 (file)
@@ -1651,7 +1651,8 @@ convert_arguments (typelist, values, name, fundecl)
                      tree type1 = TREE_TYPE (would_have_been);
 
                      if (TREE_CODE (type) == ENUMERAL_TYPE
-                         && type == TREE_TYPE (val))
+                         && (TYPE_MAIN_VARIANT (type)
+                             == TYPE_MAIN_VARIANT (TREE_TYPE (val))))
                        /* No warning if function asks for enum
                           and the actual arg is that enum type.  */
                        ;
diff --git a/gcc/testsuite/gcc.dg/Wconversion.c b/gcc/testsuite/gcc.dg/Wconversion.c
new file mode 100644 (file)
index 0000000..7cbcb6a
--- /dev/null
@@ -0,0 +1,20 @@
+/* Source: PR 137.
+
+   We would not warn about passing an enum, but would warn about
+   passing a enum that was part of an array.  TYPE_MAIN_VARIANT was
+   not used in the appropriate place in the warning code.  */
+
+/* { dg-do compile } */
+/* { dg-options -Wconversion } */
+
+typedef enum { a } __attribute__((packed)) t;
+void f(t x) {}
+
+int main(void)
+{
+  t x[2], y;
+  f(x[0]);                     /* { dg-bogus "different width" } */
+  f(y);                                /* { dg-bogus "different width" } */
+  return 0;
+}
+