re PR c++/11517 (g++ fails to properly convert pointer expressions in conditional...
authorMark Mitchell <mark@codesourcery.com>
Wed, 23 Jul 2003 18:44:43 +0000 (18:44 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Wed, 23 Jul 2003 18:44:43 +0000 (18:44 +0000)
PR c++/11517
* call.c (build_conditional_expr): Use perform_implicit_conversion
and error_operand_p.  Robustify.
* typeck.c (build_unary_op): Use perform_implicit_conversion.

PR c++/11517
* g++.dg/expr/cond2.C: New test.

From-SVN: r69715

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/expr/cond2.C [new file with mode: 0644]

index 45f1751..1ef39bf 100644 (file)
@@ -1,3 +1,10 @@
+2003-07-23  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/11517
+       * call.c (build_conditional_expr): Use perform_implicit_conversion
+       and error_operand_p.  Robustify.
+       * typeck.c (build_unary_op): Use perform_implicit_conversion.
+
 2003-07-23  Nathan Sidwell  <nathan@codesourcery.com>
 
        PR c++/10953
index cbfc5c3..dddd7b8 100644 (file)
@@ -3072,16 +3072,13 @@ build_conditional_expr (tree arg1, tree arg2, tree arg3)
   
      The first expr ession is implicitly converted to bool (clause
      _conv_).  */
-  arg1 = cp_convert (boolean_type_node, arg1);
+  arg1 = perform_implicit_conversion (boolean_type_node, arg1);
 
   /* If something has already gone wrong, just pass that fact up the
      tree.  */
-  if (arg1 == error_mark_node 
-      || arg2 == error_mark_node 
-      || arg3 == error_mark_node 
-      || TREE_TYPE (arg1) == error_mark_node
-      || TREE_TYPE (arg2) == error_mark_node
-      || TREE_TYPE (arg3) == error_mark_node)
+  if (error_operand_p (arg1)
+      || error_operand_p (arg2)
+      || error_operand_p (arg3))
     return error_mark_node;
 
   /* [expr.cond]
@@ -3333,6 +3330,8 @@ build_conditional_expr (tree arg1, tree arg2, tree arg3)
     {
       result_type = composite_pointer_type (arg2_type, arg3_type, arg2,
                                            arg3, "conditional expression");
+      if (result_type == error_mark_node)
+       return error_mark_node;
       arg2 = perform_implicit_conversion (result_type, arg2);
       arg3 = perform_implicit_conversion (result_type, arg3);
     }
index 0356cb7..eb04f88 100644 (file)
@@ -3663,7 +3663,7 @@ build_unary_op (enum tree_code code, tree xarg, int noconvert)
       break;
 
     case TRUTH_NOT_EXPR:
-      arg = cp_convert (boolean_type_node, arg);
+      arg = perform_implicit_conversion (boolean_type_node, arg);
       val = invert_truthvalue (arg);
       if (arg != error_mark_node)
        return val;
index a87abef..354fa81 100644 (file)
@@ -1,5 +1,8 @@
 2003-07-23  Mark Mitchell  <mark@codesourcery.com>
 
+       PR c++/11517
+       * g++.dg/expr/cond2.C: New test.
+       
        PR optimization/10679
        * g++.dg/opt/inline4.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/expr/cond2.C b/gcc/testsuite/g++.dg/expr/cond2.C
new file mode 100644 (file)
index 0000000..d9c2e70
--- /dev/null
@@ -0,0 +1,12 @@
+struct Term { };
+struct Boolean : Term {
+  explicit Boolean(bool);
+};
+struct IsZero : Term {
+  Term *eval();
+};
+Term*
+IsZero::eval()
+{
+  return true ? new Boolean(false) : this; // { dg-error "" }
+}