re PR c++/35334 (Broken diagnostic for complex cast)
authorJakub Jelinek <jakub@redhat.com>
Wed, 12 Nov 2008 08:18:45 +0000 (09:18 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 12 Nov 2008 08:18:45 +0000 (09:18 +0100)
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

gcc/ChangeLog
gcc/c-pretty-print.c
gcc/cp/ChangeLog
gcc/cp/error.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/error29.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr35334.c [new file with mode: 0644]

index 6bb36f5de6fa7beb7422e84ed5dc71210965d50f..b8c38c1f5e69e9e1ce24db7c15bc340bc1c36aea 100644 (file)
@@ -1,5 +1,9 @@
 2008-11-12  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/35334
+       * c-pretty-print.c (pp_c_complex_expr): New function.
+       (pp_c_postfix_expression) <case COMPLEX_EXPR>: Call it.
+
        PR target/35366
        * expr.c (expand_expr_addr_expr_1): If EXP needs bigger alignment
        than INNER and INNER is a constant, forcibly align INNER as much
index 67a466ba74934d5027d8b36651d108708484241e..9ee2738ca82ac2acb75579abdcd5913bebb5290c 100644 (file)
@@ -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.  */
index 81941e262f1fd15a2c50e1d4f1256de126924c42..8cfdf61255e5c80935f90df8a42c26664f972d36 100644 (file)
@@ -1,3 +1,8 @@
+2008-11-12  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/35334
+       * error.c (dump_expr): Handle COMPLEX_EXPR.
+
 2008-11-10  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/38021
index 4064ad400e2482e6512c0572acb9f6f2f915db3c..3aa9b595fa7ce2416966e74640f2f7a1c1464703 100644 (file)
@@ -2068,6 +2068,7 @@ dump_expr (tree t, int flags)
     case UNGE_EXPR:
     case UNEQ_EXPR:
     case LTGT_EXPR:
+    case COMPLEX_EXPR:
       pp_expression (cxx_pp, t);
       break;
 
index df1cb8621f135f04a6b6f935de705a11fea5b37b..922525fea728e25187f5f0e9b63b18696c4c0ea3 100644 (file)
@@ -1,3 +1,9 @@
+2008-11-12  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/35334
+       * gcc.dg/pr35334.c: New test.
+       * g++.dg/other/error29.C: New test.
+
 2008-11-12  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/38065
diff --git a/gcc/testsuite/g++.dg/other/error29.C b/gcc/testsuite/g++.dg/other/error29.C
new file mode 100644 (file)
index 0000000..a464058
--- /dev/null
@@ -0,0 +1,21 @@
+// PR c++/35334
+// { dg-do compile }
+// { dg-bogus "not supported by" "" { target *-*-* } 0 }
+
+__complex__ unsigned int i;
+int j;
+char k;
+__complex__ double l;
+double m;
+float n;
+
+void
+foo ()
+{
+  ((__complex__ int)i)();              // { dg-error "cannot be used as a function" }
+  ((__complex__ int)j)();              // { dg-error "cannot be used as a function" }
+  ((__complex__ int)k)();              // { dg-error "cannot be used as a function" }
+  ((__complex__ long double)l)();      // { dg-error "cannot be used as a function" }
+  ((__complex__ long double)m)();      // { dg-error "cannot be used as a function" }
+  ((__complex__ long double)n)();      // { dg-error "cannot be used as a function" }
+}
diff --git a/gcc/testsuite/gcc.dg/pr35334.c b/gcc/testsuite/gcc.dg/pr35334.c
new file mode 100644 (file)
index 0000000..d4c642e
--- /dev/null
@@ -0,0 +1,22 @@
+/* PR c++/35334 */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99" } */
+/* { dg-bogus "not supported by" "" { target *-*-* } 0 } */
+
+__complex__ unsigned int i;
+int j;
+char k;
+__complex__ double l;
+double m;
+float n;
+
+void
+foo ()
+{
+  ((__complex__ int)i)();              /* { dg-error "is not a function" } */
+  ((__complex__ int)j)();              /* { dg-error "is not a function" } */
+  ((__complex__ int)k)();              /* { dg-error "is not a function" } */
+  ((__complex__ long double)l)();      /* { dg-error "is not a function" } */
+  ((__complex__ long double)m)();      /* { dg-error "is not a function" } */
+  ((__complex__ long double)n)();      /* { dg-error "is not a function" } */
+}