This is the mail archive of the gcc-patches@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]
Other format: [Raw text]

[C++] Fix 18949


This patch fixes my recent breakage caused by 18803.  We need to bash
the result of conversions to reference types even in templates.  Unfortunately,
instantiation of that can also result in bashing the reference type, so
we must check when tsubsting the INDIRECT_REF that that has not already
occurred.  (It looked too involved to stop the instantiation doing the
dereference, as it can involve overload resolution and so would extend
into several pieces of the compiler.)

booted & tested on i686-pc-linux-gnu.

nathan
--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.956
diff -c -3 -p -r1.956 pt.c
*** cp/pt.c	8 Dec 2004 08:35:41 -0000	1.956
--- cp/pt.c	14 Dec 2004 15:15:42 -0000
*************** tsubst_copy_and_build (tree t, 
*** 8395,8402 ****
  
  	if (REFERENCE_REF_P (t))
  	  {
! 	    gcc_assert (TREE_CODE (TREE_TYPE (r)) == REFERENCE_TYPE);
! 	    r = convert_from_reference (r);
  	  }
  	else
  	  r = build_x_indirect_ref (r, "unary *");
--- 8395,8405 ----
  
  	if (REFERENCE_REF_P (t))
  	  {
! 	    /* A type conversion to reference type will be enclosed in
! 	       such an indirect ref, but the substitution of the cast
! 	       will have also added such an indirect ref.  */
! 	    if (TREE_CODE (TREE_TYPE (r)) == REFERENCE_TYPE)
! 	      r = convert_from_reference (r);
  	  }
  	else
  	  r = build_x_indirect_ref (r, "unary *");
Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.603
diff -c -3 -p -r1.603 typeck.c
*** cp/typeck.c	9 Dec 2004 10:34:17 -0000	1.603
--- cp/typeck.c	14 Dec 2004 15:15:55 -0000
*************** build_static_cast (tree type, tree expr)
*** 4767,4773 ****
        expr = build_min (STATIC_CAST_EXPR, type, expr);
        /* We don't know if it will or will not have side effects.  */
        TREE_SIDE_EFFECTS (expr) = 1;
!       return expr;
      }
  
    /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
--- 4767,4773 ----
        expr = build_min (STATIC_CAST_EXPR, type, expr);
        /* We don't know if it will or will not have side effects.  */
        TREE_SIDE_EFFECTS (expr) = 1;
!       return convert_from_reference (expr);
      }
  
    /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
*************** build_reinterpret_cast (tree type, tree 
*** 4983,4989 ****
  	  && type_dependent_expression_p (expr))
  	/* There might turn out to be side effects inside expr.  */
  	TREE_SIDE_EFFECTS (t) = 1;
!       return t;
      }
  
    return build_reinterpret_cast_1 (type, expr, /*c_cast_p=*/false,
--- 4983,4989 ----
  	  && type_dependent_expression_p (expr))
  	/* There might turn out to be side effects inside expr.  */
  	TREE_SIDE_EFFECTS (t) = 1;
!       return convert_from_reference (t);
      }
  
    return build_reinterpret_cast_1 (type, expr, /*c_cast_p=*/false,
*************** build_const_cast (tree type, tree expr)
*** 5111,5117 ****
  	  && type_dependent_expression_p (expr))
  	/* There might turn out to be side effects inside expr.  */
  	TREE_SIDE_EFFECTS (t) = 1;
!       return t;
      }
  
    return build_const_cast_1 (type, expr, /*complain=*/true,
--- 5111,5117 ----
  	  && type_dependent_expression_p (expr))
  	/* There might turn out to be side effects inside expr.  */
  	TREE_SIDE_EFFECTS (t) = 1;
!       return convert_from_reference (t);
      }
  
    return build_const_cast_1 (type, expr, /*complain=*/true,
*************** build_c_cast (tree type, tree expr)
*** 5137,5143 ****
  			  tree_cons (NULL_TREE, value, NULL_TREE));
        /* We don't know if it will or will not have side effects.  */
        TREE_SIDE_EFFECTS (t) = 1;
!       return t;
      }
  
    /* Casts to a (pointer to a) specific ObjC class (or 'id' or
--- 5137,5143 ----
  			  tree_cons (NULL_TREE, value, NULL_TREE));
        /* We don't know if it will or will not have side effects.  */
        TREE_SIDE_EFFECTS (t) = 1;
!       return convert_from_reference (t);
      }
  
    /* Casts to a (pointer to a) specific ObjC class (or 'id' or
// { dg-do compile }

// Copyright (C) 2004 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 14 Dec 2004 <nathan@codesourcery.com>

// PR 18949. Forgot to convert from reference.
// Origin: Volker Reichelt <reichelt@gcc.gnu.org>

struct A
{
    void foo();
};

template<int> void bar(A& a)
{
    const_cast<A&>(a).foo();
    static_cast<A&>(a).foo();
    reinterpret_cast<A&>(a).foo();
    ((A&)a).foo();
}

template void bar<0>(A& a);

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