This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: cast to bool not done



Thanks.  Fixed with the attached patch, which also has a couple of
minor cleanups and catches a copule of errors we missed before.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

1999-09-12  Mark Mitchell  <mark@codesourcery.com>

	* call.c (implicit_conversion): Robustify.  Handle OFFSET_REFs.
	* cvt.c (ocp_convert): Complete the from and destination types.
	Adjust warning about functions always being `true' in conditionals.
	* decl.c (duplicate_decls): Don't play funny games with abort.
	* error.c (dump_expr): Handle OVERLOADs.
	* spew.c (probe_obstack): Remove.
	* typeck.c (condition_conversion): Use perform_implicit_conversion.
	
Index: g++.mike/warn8.C
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/testsuite/g++.old-deja/g++.mike/warn8.C,v
retrieving revision 1.2
diff -c -p -r1.2 warn8.C
*** warn8.C	1998/12/16 21:49:37	1.2
--- warn8.C	1999/09/13 00:33:48
*************** void test() {
*** 10,19 ****
    bool (foo::* pmf)() = &foo::test;
    bool (*pf)() = func;
  
!   if (A.test) ;			// WARNING - 
    if (func) ;			// WARNING - 
!   if (bool(A.test)) ;		// WARNING - 
!   if (bool(func)) ;
    if (pmf) ;
    if (pf) ;
  }
--- 10,19 ----
    bool (foo::* pmf)() = &foo::test;
    bool (*pf)() = func;
  
!   if (A.test) ;			// ERROR - 
    if (func) ;			// WARNING - 
!   if (bool(A.test)) ;		// ERROR - 
!   if (bool(func)) ;             // WARNING - 
    if (pmf) ;
    if (pf) ;
  }
Index: g++.pt/cond3.C
===================================================================
RCS file: cond3.C
diff -N cond3.C
*** /dev/null	Sat Dec  5 20:30:03 1998
--- cond3.C	Sun Sep 12 17:33:48 1999
***************
*** 0 ****
--- 1,25 ----
+ // Build don't link:
+ // Origin: Loring Holden <lsh@lsh.cs.brown.edu>
+ 
+ template <class T>
+ class REFptr {
+    public:
+       operator T* () const;
+ };
+ 
+ class CamFocus;
+ typedef REFptr<CamFocus> CamFocusptr;
+ 
+ class CamFocus {
+    protected:
+       static CamFocusptr  _focus;
+    public :
+       static CamFocusptr &cur() { return _focus; }
+ };
+ 
+ void
+ test()  
+ {
+    if (CamFocus::cur()) {
+    }
+ }
Index: call.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/call.c,v
retrieving revision 1.168
diff -c -p -r1.168 call.c
*** call.c	1999/09/09 06:16:29	1.168
--- call.c	1999/09/12 21:13:29
*************** implicit_conversion (to, from, expr, fla
*** 1151,1156 ****
--- 1151,1170 ----
    tree conv;
    struct z_candidate *cand;
  
+   /* Resolve expressions like `A::p' that we thought might become
+      pointers-to-members.  */
+   if (expr && TREE_CODE (expr) == OFFSET_REF)
+     {
+       expr = resolve_offset_ref (expr);
+       from = TREE_TYPE (expr);
+     }
+ 
+   if (from == error_mark_node || to == error_mark_node
+       || expr == error_mark_node)
+     return NULL_TREE;
+ 
+   /* Make sure both the FROM and TO types are complete so that
+      user-defined conversions are available.  */
    complete_type (from);
    complete_type (to);
  
Index: cvt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cvt.c,v
retrieving revision 1.66
diff -c -p -r1.66 cvt.c
*** cvt.c	1999/09/12 01:12:57	1.66
--- cvt.c	1999/09/12 21:13:30
*************** ocp_convert (type, expr, convtype, flags
*** 675,680 ****
--- 675,683 ----
        || TREE_TYPE (e) == error_mark_node)
      return error_mark_node;
  
+   complete_type (type);
+   complete_type (TREE_TYPE (expr));
+ 
    if (TREE_READONLY_DECL_P (e))
      e = decl_constant_value (e);
  
*************** ocp_convert (type, expr, convtype, flags
*** 742,751 ****
  	}
        if (code == BOOLEAN_TYPE)
  	{
  	  /* Common Ada/Pascal programmer's mistake.  We always warn
               about this since it is so bad.  */
  	  if (TREE_CODE (expr) == FUNCTION_DECL)
! 	    cp_warning ("the address of `%D', will always be `true'", expr);
  	  return truthvalue_conversion (e);
  	}
        return fold (convert_to_integer (type, e));
--- 745,761 ----
  	}
        if (code == BOOLEAN_TYPE)
  	{
+ 	  tree fn = NULL_TREE;
+ 
  	  /* Common Ada/Pascal programmer's mistake.  We always warn
               about this since it is so bad.  */
  	  if (TREE_CODE (expr) == FUNCTION_DECL)
! 	    fn = expr;
! 	  else if (TREE_CODE (expr) == ADDR_EXPR 
! 		   && TREE_CODE (TREE_OPERAND (expr, 0)) == FUNCTION_DECL)
! 	    fn = TREE_OPERAND (expr, 0);
! 	  if (fn)
! 	    cp_warning ("the address of `%D', will always be `true'", fn);
  	  return truthvalue_conversion (e);
  	}
        return fold (convert_to_integer (type, e));
Index: decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.448
diff -c -p -r1.448 decl.c
*** decl.c	1999/09/12 15:15:54	1.448
--- decl.c	1999/09/12 21:13:39
*************** duplicate_decls (newdecl, olddecl)
*** 3414,3425 ****
        if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
  	DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
  
!       /* Keep the old rtl since we can safely use it, unless it's the
! 	 call to abort() used for abstract virtuals.  */
!       if ((DECL_LANG_SPECIFIC (olddecl)
! 	   && !DECL_ABSTRACT_VIRTUAL_P (olddecl))
! 	  || DECL_RTL (olddecl) != DECL_RTL (abort_fndecl))
! 	DECL_RTL (newdecl) = DECL_RTL (olddecl);
  
        pop_obstacks ();
      }
--- 3414,3421 ----
        if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
  	DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
  
!       /* Keep the old rtl since we can safely use it.  */
!       DECL_RTL (newdecl) = DECL_RTL (olddecl);
  
        pop_obstacks ();
      }
Index: error.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/error.c,v
retrieving revision 1.87
diff -c -p -r1.87 error.c
*** error.c	1999/08/29 13:47:37	1.87
--- error.c	1999/09/12 21:13:40
*************** dump_expr (t, nop)
*** 1272,1277 ****
--- 1272,1278 ----
      case FUNCTION_DECL:
      case TEMPLATE_DECL:
      case NAMESPACE_DECL:
+     case OVERLOAD:
        dump_decl (t, -1);
        break;
  
Index: spew.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/spew.c,v
retrieving revision 1.23
diff -c -p -r1.23 spew.c
*** spew.c	1999/09/12 02:45:30	1.23
--- spew.c	1999/09/12 21:13:40
*************** struct token  {
*** 47,53 ****
  };
  
  static int do_aggr PROTO((void));
- static int probe_obstack PROTO((struct obstack *, tree, unsigned int));
  static void scan_tokens PROTO((unsigned int));
  
  #ifdef SPEW_DEBUG
--- 47,52 ----
*************** scan_tokens (n)
*** 196,225 ****
  	    }
  	}
      }
- }
- 
- /* Like _obstack_allocated_p, but stop after checking NLEVELS chunks.  */
- 
- static int
- probe_obstack (h, obj, nlevels)
-      struct obstack *h;
-      tree obj;
-      unsigned int nlevels;
- {
-   register struct _obstack_chunk*  lp;	/* below addr of any objects in this chunk */
-   register struct _obstack_chunk*  plp;	/* point to previous chunk if any */
- 
-   lp = (h)->chunk;
-   /* We use >= rather than > since the object cannot be exactly at
-      the beginning of the chunk but might be an empty object exactly
-      at the end of an adjacent chunk.  */
-   for (; nlevels != 0 && lp != 0 && ((tree)lp >= obj || (tree)lp->limit < obj);
-        nlevels -= 1)
-     {
-       plp = lp->prev;
-       lp = plp;      
-     }
-   return nlevels != 0 && lp != 0;
  }
  
  /* from lex.c: */
--- 195,200 ----
Index: typeck.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/typeck.c,v
retrieving revision 1.207
diff -c -p -r1.207 typeck.c
*** typeck.c	1999/09/10 08:52:06	1.207
--- typeck.c	1999/09/12 21:13:44
*************** condition_conversion (expr)
*** 4336,4342 ****
    tree t;
    if (processing_template_decl)
      return expr;
!   t = cp_convert (boolean_type_node, expr);
    t = fold (build1 (CLEANUP_POINT_EXPR, boolean_type_node, t));
    return t;
  }
--- 4336,4342 ----
    tree t;
    if (processing_template_decl)
      return expr;
!   t = perform_implicit_conversion (boolean_type_node, expr);
    t = fold (build1 (CLEANUP_POINT_EXPR, boolean_type_node, t));
    return t;
  }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]