diff options
author | Jakub Jelinek <jakub@redhat.com> | 2008-11-12 09:18:45 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2008-11-12 09:18:45 +0100 |
commit | 66e681911005962f96d56daf1a2b80bfe89cfbd2 (patch) | |
tree | 001e057e0e70c8a90aafba8c44da9fd2ef973064 /gcc/c-pretty-print.c | |
parent | 8ebec1a5dd8a729cf24ad3cc708d9193392e8451 (diff) | |
download | gcc-66e681911005962f96d56daf1a2b80bfe89cfbd2.zip gcc-66e681911005962f96d56daf1a2b80bfe89cfbd2.tar.gz gcc-66e681911005962f96d56daf1a2b80bfe89cfbd2.tar.bz2 |
re PR c++/35334 (Broken diagnostic for complex cast)
PR c++/35334
* c-pretty-print.c (pp_c_complex_expr): New function.
(pp_c_postfix_expression) <case COMPLEX_EXPR>: Call it.
* error.c (dump_expr): Handle COMPLEX_EXPR.
* gcc.dg/pr35334.c: New test.
* g++.dg/other/error29.C: New test.
From-SVN: r141783
Diffstat (limited to 'gcc/c-pretty-print.c')
-rw-r--r-- | gcc/c-pretty-print.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/gcc/c-pretty-print.c b/gcc/c-pretty-print.c index 67a466b..9ee2738 100644 --- a/gcc/c-pretty-print.c +++ b/gcc/c-pretty-print.c @@ -975,6 +975,46 @@ pp_c_compound_literal (c_pretty_printer *pp, tree e) } } +/* Pretty-print a COMPLEX_EXPR expression. */ + +static void +pp_c_complex_expr (c_pretty_printer *pp, tree e) +{ + /* Handle a few common special cases, otherwise fallback + to printing it as compound literal. */ + tree type = TREE_TYPE (e); + tree realexpr = TREE_OPERAND (e, 0); + tree imagexpr = TREE_OPERAND (e, 1); + + /* Cast of an COMPLEX_TYPE expression to a different COMPLEX_TYPE. */ + if (TREE_CODE (realexpr) == NOP_EXPR + && TREE_CODE (imagexpr) == NOP_EXPR + && TREE_TYPE (realexpr) == TREE_TYPE (type) + && TREE_TYPE (imagexpr) == TREE_TYPE (type) + && TREE_CODE (TREE_OPERAND (realexpr, 0)) == REALPART_EXPR + && TREE_CODE (TREE_OPERAND (imagexpr, 0)) == IMAGPART_EXPR + && TREE_OPERAND (TREE_OPERAND (realexpr, 0), 0) + == TREE_OPERAND (TREE_OPERAND (imagexpr, 0), 0)) + { + pp_c_type_cast (pp, type); + pp_expression (pp, TREE_OPERAND (TREE_OPERAND (realexpr, 0), 0)); + return; + } + + /* Cast of an scalar expression to COMPLEX_TYPE. */ + if ((integer_zerop (imagexpr) || real_zerop (imagexpr)) + && TREE_TYPE (realexpr) == TREE_TYPE (type)) + { + pp_c_type_cast (pp, type); + if (TREE_CODE (realexpr) == NOP_EXPR) + realexpr = TREE_OPERAND (realexpr, 0); + pp_expression (pp, realexpr); + return; + } + + pp_c_compound_literal (pp, e); +} + /* constant: integer-constant floating-constant @@ -1406,10 +1446,13 @@ pp_c_postfix_expression (c_pretty_printer *pp, tree e) case COMPLEX_CST: case VECTOR_CST: - case COMPLEX_EXPR: pp_c_compound_literal (pp, e); break; + case COMPLEX_EXPR: + pp_c_complex_expr (pp, e); + break; + case COMPOUND_LITERAL_EXPR: e = DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e)); /* Fall through. */ |