This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch for PR c/2735
- To: <gcc-patches at gcc dot gnu dot org>
- Subject: Patch for PR c/2735
- From: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>
- Date: Tue, 5 Jun 2001 11:17:18 +0100 (BST)
This patch fixes PR c/2735, a problem with the GCC extension of
casting structs and unions to their own types.
Bootstrapped with no regressions on i686-pc-linux-gnu. Installed on
mainline.
2001-06-05 Joseph S. Myers <jsm28@cam.ac.uk>
* c-typeck.c (build_c_cast): Use TYPE_MAIN_VARIANT when checking
for casting an aggregate to its own type. Fixes PR c/2735.
testsuite:
2001-06-05 Joseph S. Myers <jsm28@cam.ac.uk>
* gcc.c-torture/compile/20010605-2.c: New test.
--- c-typeck.c.orig Fri May 25 07:05:01 2001
+++ c-typeck.c Mon Jun 4 22:54:42 2001
@@ -3721,7 +3721,7 @@ build_c_cast (type, expr)
return error_mark_node;
}
- if (type == TREE_TYPE (value))
+ if (type == TYPE_MAIN_VARIANT (TREE_TYPE (value)))
{
if (pedantic)
{
--- testsuite/gcc.c-torture/compile/20010605-2.c.orig Mon Mar 26 23:57:02 2001
+++ testsuite/gcc.c-torture/compile/20010605-2.c Mon Jun 4 22:59:07 2001
@@ -0,0 +1,17 @@
+/* Origin: Joseph Myers <jsm28@cam.ac.uk>. */
+/* As an extension, GCC allows a struct or union to be cast to its own
+ type, but failed to allow this when a typedef was involved.
+ Reported as PR c/2735 by <cowan@ccil.org>. */
+union u { int i; };
+typedef union u uu;
+union u a;
+uu b;
+
+void
+foo (void)
+{
+ a = (union u) b;
+ a = (uu) b;
+ b = (union u) a;
+ b = (uu) a;
+}
--
Joseph S. Myers
jsm28@cam.ac.uk