gcc/gcc43-pr34965.patch
Jakub Jelinek 18792bedb3 4.3.0-0.6
2008-01-25 17:43:01 +00:00

136 lines
4.2 KiB
Diff

2008-01-25 Jakub Jelinek <jakub@redhat.com>
PR c++/34965
* c-pretty-print.c (pp_c_exclusive_or_expression): Handle
TRUTH_XOR_EXPR.
(pp_c_logical_and_expression): Handle TRUTH_AND_EXPR.
(pp_c_logical_or_expression): Handle TRUTH_OR_EXPR.
(pp_c_expression): Handle TRUTH_AND_EXPR, TRUTH_OR_EXPR
and TRUTH_XOR_EXPR.
* error.c (dump_expr): Handle TRUTH_AND_EXPR, TRUTH_OR_EXPR
and TRUTH_XOR_EXPR.
* gcc.dg/pr34965.c: New test.
* g++.dg/other/error24.C: New test.
--- gcc/c-pretty-print.c.jj 2007-08-28 11:38:37.000000000 +0200
+++ gcc/c-pretty-print.c 2008-01-25 17:41:06.000000000 +0100
@@ -1,5 +1,6 @@
/* Subroutines common to both C and C++ pretty-printers.
- Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
+ Free Software Foundation, Inc.
Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
This file is part of GCC.
@@ -1737,10 +1738,14 @@ pp_c_and_expression (c_pretty_printer *p
static void
pp_c_exclusive_or_expression (c_pretty_printer *pp, tree e)
{
- if (TREE_CODE (e) == BIT_XOR_EXPR)
+ if (TREE_CODE (e) == BIT_XOR_EXPR
+ || TREE_CODE (e) == TRUTH_XOR_EXPR)
{
pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0));
- pp_c_maybe_whitespace (pp);
+ if (TREE_CODE (e) == BIT_XOR_EXPR)
+ pp_c_maybe_whitespace (pp);
+ else
+ pp_c_whitespace (pp);
pp_carret (pp);
pp_c_whitespace (pp);
pp_c_and_expression (pp, TREE_OPERAND (e, 1));
@@ -1775,7 +1780,8 @@ pp_c_inclusive_or_expression (c_pretty_p
static void
pp_c_logical_and_expression (c_pretty_printer *pp, tree e)
{
- if (TREE_CODE (e) == TRUTH_ANDIF_EXPR)
+ if (TREE_CODE (e) == TRUTH_ANDIF_EXPR
+ || TREE_CODE (e) == TRUTH_AND_EXPR)
{
pp_c_logical_and_expression (pp, TREE_OPERAND (e, 0));
pp_c_whitespace (pp);
@@ -1794,7 +1800,8 @@ pp_c_logical_and_expression (c_pretty_pr
void
pp_c_logical_or_expression (c_pretty_printer *pp, tree e)
{
- if (TREE_CODE (e) == TRUTH_ORIF_EXPR)
+ if (TREE_CODE (e) == TRUTH_ORIF_EXPR
+ || TREE_CODE (e) == TRUTH_OR_EXPR)
{
pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
pp_c_whitespace (pp);
@@ -1963,6 +1970,7 @@ pp_c_expression (c_pretty_printer *pp, t
break;
case BIT_XOR_EXPR:
+ case TRUTH_XOR_EXPR:
pp_c_exclusive_or_expression (pp, e);
break;
@@ -1971,10 +1979,12 @@ pp_c_expression (c_pretty_printer *pp, t
break;
case TRUTH_ANDIF_EXPR:
+ case TRUTH_AND_EXPR:
pp_c_logical_and_expression (pp, e);
break;
case TRUTH_ORIF_EXPR:
+ case TRUTH_OR_EXPR:
pp_c_logical_or_expression (pp, e);
break;
--- gcc/cp/error.c.jj 2008-01-22 15:19:30.000000000 +0100
+++ gcc/cp/error.c 2008-01-25 18:20:30.000000000 +0100
@@ -2083,6 +2083,16 @@ dump_expr (tree t, int flags)
pp_expression (cxx_pp, t);
break;
+ case TRUTH_AND_EXPR:
+ case TRUTH_OR_EXPR:
+ case TRUTH_XOR_EXPR:
+ if (flags & TFF_EXPR_IN_PARENS)
+ pp_cxx_left_paren (cxx_pp);
+ pp_expression (cxx_pp, t);
+ if (flags & TFF_EXPR_IN_PARENS)
+ pp_cxx_right_paren (cxx_pp);
+ break;
+
case OBJ_TYPE_REF:
dump_expr (resolve_virtual_fun_from_obj_type_ref (t), flags);
break;
--- gcc/testsuite/gcc.dg/pr34965.c.jj 2008-01-25 18:25:46.000000000 +0100
+++ gcc/testsuite/gcc.dg/pr34965.c 2008-01-25 18:26:05.000000000 +0100
@@ -0,0 +1,13 @@
+/* PR c++/34965 */
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+
+int foo (int);
+
+void
+bar (int i, int j, double k)
+{
+ foo (i && j) (); /* { dg-error "\\(i != 0 \\&\\& j != 0\\)" } */
+ foo (!i || !j) (); /* { dg-error "\\(i == 0 \\|\\| j == 0\\)" } */
+ foo (!i == !j) (); /* { dg-error "\\(i != 0 \\^ j == 0\\)" } */
+}
--- gcc/testsuite/g++.dg/other/error24.C.jj 2008-01-25 14:38:12.000000000 +0100
+++ gcc/testsuite/g++.dg/other/error24.C 2008-01-25 18:25:01.000000000 +0100
@@ -0,0 +1,13 @@
+// PR c++/34965
+// { dg-do compile }
+// { dg-options "-O" }
+
+int foo (int);
+
+void
+bar (int i, int j, double k)
+{
+ foo (i && j) (); // { dg-error "\\(i != 0 \\&\\& j != 0\\)" }
+ foo (!i || !j) (); // { dg-error "\\(i == 0 \\|\\| j == 0\\)" }
+ foo (!i == !j) (); // { dg-error "\\(i != 0 \\^ j == 0\\)" }
+}