Bug 45 - Template Specialization
|
Bug#:
45
|
Product: gcc
|
Version: 2.95.2
|
|
Host:
|
Target:
|
Build:
|
|
Status: RESOLVED
|
Severity: normal
|
Priority: P3
|
|
Resolution: FIXED
|
Assigned To: nathan@gcc.gnu.org
|
Reported By: martin@loewis.home.cs.tu-berlin.de
|
|
Component: c++
|
Target Milestone: ---
|
|
Summary: Template Specialization
|
|
Keywords: rejects-valid
|
|
Opened: 2000-03-05 02:16
|
|
Description:
|
Last confirmed: 2002-12-31 00:00
|
Opened: 2000-03-05 02:16
|
Original-Message-ID: <37E78776.36C42062@carter.net>
Date: Tue, 21 Sep 1999 08:26:14 -0500
[Original report simplified]
Under gcc-2.95.1, on 'i686-pc-linux-gnu' the code below returns a
syntax error on compilation. This same code compiled fine way back
around egcs-1.0, but has been broken since 1.1 or thereabouts. For
the curious, this is part of the type promotion code for a
template-metaprogram implementation of lisp I'm working on (maybe a
future Master's Thesis project).
Casey Carter
Release:
2.95.2
How-To-Repeat:
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 N, char C>
class NumPromote< Int<N>, Char<C> > {
public:
typedef Int<N> val;
typedef Int<C> val1;
};
static NumPromote< Char<69>, Int<0> >::val ci0;
static NumPromote< Char<69>, Int<0> >::val1 ci1;
static NumPromote< Int<0>, Char<69> >::val ic0;
static NumPromote< Int<0>, Char<69> >::val1 ic1;
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed as a bug
Responsible-Changed-From-To: unassigned->nathan
Responsible-Changed-Why: Patch in progress
From: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
To: gcc-bugs@gcc.gnu.org, <gcc-gnats@gcc.gnu.org>
Cc:
Subject: Re: c++/45: Template Specialization
Date: Tue, 22 Oct 2002 18:51:23 -0500 (CDT)
Someone should re-name this report to
"Matching of partial specialization of classes"
Here's a redux:
-----------------------------------------
template <int N> struct Int {};
template <char C> struct Char{};
template <typename A, typename B> struct X;
template <char C, int N> struct X< Char<C>, Int<N> > { typedef Int<C> val; };
template <int N, char C> struct X< Int<N>, Char<C> > { typedef Int<N> val; };
X< Int<0>, Char<'1'> >::val i;
----------------------------------------
In ways I don't understand, this bug goes away if in the declaration of
the second partial specialization, "int N" and "char C" is reversed,
something that should have absolutely no effect on matching of templates.
In some other ways I do not understand either, the problem also goes away
if I change the template argument of "Char" from "char" to "int",
something that should also not affect matching, but does.
Regards
Wolfgang
-------------------------------------------------------------------------
Wolfgang Bangerth email: bangerth@ticam.utexas.edu
www: http://www.ticam.utexas.edu/~bangerth
State-Changed-From-To: analyzed->closed
State-Changed-Why: 2002-12-26 Nathan Sidwell <nathan@codesourcery.com>
PR c++/45, c++/3784
* tree.c (cp_tree_equal, TEMPLATE_PARM_INDEX): The types must be
the same too.