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++ PATCH] Fix PR 45


Hi,
this fixes PR 45. Template non-type parameter only match if the types
are the same too.  Here the second partial specialization of Int<N1>
gets confused with the first partial specialization of Int<C>.

booted & tested on i686-pc-linux-gnu, ok for mainline?

nathan
-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
           The voices in my head told me to say this
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk
2001-11-30  Nathan Sidwell  <nathan@codesourcery.com>

	* tree.c (cp_tree_equal, TEMPLATE_PARM_INDEX): Compare types of
	the decls too.

Index: cp/tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/tree.c,v
retrieving revision 1.261
diff -c -3 -p -r1.261 tree.c
*** tree.c	2001/11/29 17:15:56	1.261
--- tree.c	2001/11/30 21:57:27
*************** cp_tree_equal (t1, t2)
*** 1652,1658 ****
  
      case TEMPLATE_PARM_INDEX:
        return TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
! 	&& TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2);
  
      case SIZEOF_EXPR:
      case ALIGNOF_EXPR:
--- 1652,1660 ----
  
      case TEMPLATE_PARM_INDEX:
        return TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
! 	&& TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2)
! 	&& same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1)),
! 			TREE_TYPE (TEMPLATE_PARM_DECL (t2)));
  
      case SIZEOF_EXPR:
      case ALIGNOF_EXPR:
// { dg-do compile }

// Copyright (C) 2000 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 30 Nov 2001 <nathan@nathan@codesourcery.com>

// PR 45

template <int N> class Int {
  public:
  typedef Int val;
};

template <char C> class Char {
  public:
  typedef Char val;
};

template <class A, class B>
class NumPromote {};

template <char C, int N>
class NumPromote< Char <C>, Int <N> > {
  public:
  typedef Int<C> val;
  typedef Int<N> val1;
};

template <int N1, char C1>
class NumPromote< Int<N1>, Char<C1> > {
  public:
  typedef Int<N1> val;
  typedef Int<C1> val1;
};

static NumPromote< Char<69>, Int<0> >::val ic0;
static NumPromote< Int<0>, Char<69> >::val ci0;
static NumPromote< Char<69>, Int<0> >::val1 ci1;
static NumPromote< Int<0>, Char<69> >::val1 ic1;

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