From f375b7a70574ae0e5900a3bfab24f4e8e2edc920 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Tue, 5 Jun 2001 11:16:57 +0100 Subject: [PATCH] re PR c/2735 (can't cast a union type defined by a typedef to itself) * 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 | 5 +++++ gcc/c-typeck.c | 2 +- gcc/testsuite/ChangeLog | 4 ++++ .../gcc.c-torture/compile/20010605-2.c | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/20010605-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a354fe8bcee..86b516d6ef4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2001-06-05 Joseph S. Myers + + * 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 * doc/texinfo.tex: Update to version 2001-05-24.08. diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 5705faafa0e..478ec43544b 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -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) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 03a8b52bcf7..14ca76fd5bc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2001-06-05 Joseph S. Myers + + * gcc.c-torture/compile/20010605-2.c: New test. + 2001-06-04 John David Anglin * 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 index 00000000000..b8d9d5892da --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/20010605-2.c @@ -0,0 +1,17 @@ +/* Origin: Joseph Myers . */ +/* 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 . */ +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; +} -- 2.30.2