This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
c: Fix PR 137.
- To: gcc-patches at gcc dot gnu dot org
- Subject: c: Fix PR 137.
- From: Neil Booth <neil at daikokuya dot demon dot co dot uk>
- Date: Fri, 26 Oct 2001 20:41:48 +0100
- Cc: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>
This fixes PR 137. OK to commit assuming no regressions?
Neil.
* c-typeck.c (convert_arguments): When comparing for enumeral
type equality, use TYPE_MAIN_VARIANT.
* gcc.dg/Wconversion.c: New tests.
Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.143
diff -u -p -r1.143 c-typeck.c
--- c-typeck.c 2001/10/24 20:10:51 1.143
+++ c-typeck.c 2001/10/26 19:35:06
@@ -1651,7 +1651,8 @@ convert_arguments (typelist, values, nam
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. */
;
Index: testsuite/gcc.dg/Wconversion.c
===================================================================
RCS file: Wconversion.c
diff -N Wconversion.c
--- /dev/null Tue May 5 13:32:27 1998
+++ Wconversion.c Fri Oct 26 12:35:06 2001
@@ -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;
+}
+