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]

C++ PATCH: typedefs breaking conversions


hi,
this is a patch for
http://egcs.cygnus.com/ml/egcs-bugs/1999-03/msg00778.html (Martin v. Loewis)
http://egcs.cygnus.com/ml/egcs-bugs/1999-03/msg00985.html (Andrew Zabolotny)

I could simplify Martin's test to the attached testcase, suitable for the
testsuite. I'm not 100% sure of the legality of Andrew's example, ClassC has
base classes -- I thought that made it non-PoD, but can't find words in the
standard to that effect (9/4 doesn't mention it). However an ICE is not an
acceptable failure mode.

In both cases the compiler was comparing types with == rather than same_type_p.
When one of the types is, or contains, a typedef, == will incorrectly say no.

There are no additional regressions on the testsuite with this patch applied to
the 19990328 snapshot on 'SunOS manao 5.6 Generic_105181-03 sun4u sparc'

Enjoy,

nathan
-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
      You can up the bandwidth, but you can't up the speed of light      
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk
egcs/gcc/cp/ChangeLog:
Wed Mar 31 11:30:43 BST 1999  Nathan Sidwell  <nathan@acm.org>

	* cvt.c (convert_pointer_to_real): Use same_type_p.
	* typeck.c (comp_target_types): Use same_type_p.

Index: egcs/gcc/cp/cvt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cvt.c,v
retrieving revision 1.55
diff -c -3 -p -r1.55 cvt.c
*** cvt.c	1999/03/26 07:44:20	1.55
--- cvt.c	1999/03/31 10:29:53
*************** convert_pointer_to_real (binfo, expr)
*** 579,585 ****
    ptr_type = cp_build_qualified_type (type,
  				      CP_TYPE_QUALS (TREE_TYPE (intype)));
    ptr_type = build_pointer_type (ptr_type);
!   if (ptr_type == TYPE_MAIN_VARIANT (intype))
      return expr;
  
    my_friendly_assert (!integer_zerop (expr), 191);
--- 579,585 ----
    ptr_type = cp_build_qualified_type (type,
  				      CP_TYPE_QUALS (TREE_TYPE (intype)));
    ptr_type = build_pointer_type (ptr_type);
!   if (same_type_p (ptr_type, TYPE_MAIN_VARIANT (intype)))
      return expr;
  
    my_friendly_assert (!integer_zerop (expr), 191);
Index: egcs/gcc/cp/typeck.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/typeck.c,v
retrieving revision 1.148
diff -c -3 -p -r1.148 typeck.c
*** typeck.c	1999/03/27 01:14:32	1.148
--- typeck.c	1999/03/31 10:30:11
*************** comp_target_types (ttl, ttr, nptrs)
*** 1021,1027 ****
  {
    ttl = TYPE_MAIN_VARIANT (ttl);
    ttr = TYPE_MAIN_VARIANT (ttr);
!   if (ttl == ttr)
      return 1;
  
    if (TREE_CODE (ttr) != TREE_CODE (ttl))
--- 1021,1027 ----
  {
    ttl = TYPE_MAIN_VARIANT (ttl);
    ttr = TYPE_MAIN_VARIANT (ttr);
!   if (same_type_p (ttl, ttr))
      return 1;
  
    if (TREE_CODE (ttr) != TREE_CODE (ttl))
// Build don't link:

// Copyright (C) 1999 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 31 Mar 1999 <nathan@acm.org>

// Make sure we see through typedefs.

typedef int Int;

void fn()
{
  int *p;
  Int *&pr2 = p;
}

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