}
}
+/* 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
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. */
--- /dev/null
+// 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" }
+}
--- /dev/null
+/* 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" } */
+}