]> gcc.gnu.org Git - gcc.git/commitdiff
re PR c/2735 (can't cast a union type defined by a typedef to itself)
authorJoseph Myers <jsm28@cam.ac.uk>
Tue, 5 Jun 2001 10:16:57 +0000 (11:16 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Tue, 5 Jun 2001 10:16:57 +0000 (11:16 +0100)
* 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:
* gcc.c-torture/compile/20010605-2.c: New test.

From-SVN: r42900

gcc/ChangeLog
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/20010605-2.c [new file with mode: 0644]

index a354fe8bcee770bbd630297e4cb62ac5136e7491..86b516d6ef41583efeed6495636bbb36080042d7 100644 (file)
@@ -1,3 +1,8 @@
+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.
+
 2001-06-05  Joseph S. Myers  <jsm28@cam.ac.uk>
 
        * doc/texinfo.tex: Update to version 2001-05-24.08.
index 5705faafa0eef777046d12482163dbac894f28a4..478ec43544b056ed47a759ad649352d789bb57a3 100644 (file)
@@ -3719,7 +3719,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)
        {
index 03a8b52bcf79575fbac12362cba671c032c7c1dc..14ca76fd5bc761ec0665e1a60580d39c0caab9d5 100644 (file)
@@ -1,3 +1,7 @@
+2001-06-05  Joseph S. Myers  <jsm28@cam.ac.uk>
+
+       * gcc.c-torture/compile/20010605-2.c: New test.
+
 2001-06-04  John David Anglin  <dave@hiauly1.hia.nrc.ca>
 
        * gcc.c-torture/execute/20010604-1.c: New test.
diff --git a/gcc/testsuite/gcc.c-torture/compile/20010605-2.c b/gcc/testsuite/gcc.c-torture/compile/20010605-2.c
new file mode 100644 (file)
index 0000000..b8d9d58
--- /dev/null
@@ -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;
+}
This page took 0.1105 seconds and 5 git commands to generate.