c++/6327: g++ problems where partial specializing nested templates
cuni@programmazione.it
cuni@programmazione.it
Tue Apr 16 10:16:00 GMT 2002
>Number: 6327
>Category: c++
>Synopsis: g++ problems where partial specializing nested templates
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Apr 16 10:16:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: g++
>Release: Thread model: single - gcc version 3.0
>Organization:
>Environment:
Mandrake 8.0 on AMD Athlon 800
>Description:
It seems that the compiler doesn't use correctly partial specialization of a nested template, even if it produce correct code when template are not nested.
>How-To-Repeat:
#include <typeinfo>
#include <iostream>
// generic template
template<class T>
struct Array_traits
{
template<class U>
struct Rebind
{
typedef U Type;
};
};
// partial specialization for arrays
template<class T, int N>
struct Array_traits<T[N]>
{
template<class U>
struct Rebind
{
typedef Array_traits<T>::Rebind<U>::Type Type[N];
};
};
int main()
{
typedef int array_of_int[10][20][30];
Array_traits<array_of_int>::Rebind<float>::Type array_of_float;
// it prints out A10_A20_A30_i
std::cout << typeid(array_of_int).name() << std::endl;
// it should print A10_A20_A30_f, but it prints A10_f
std::cout << typeid(array_of_float).name() << std::endl;
}
>Fix:
Here is a work-around that doesn't use nested templates:
// generic template
template<class T, class U>
struct Array_rebind
{
typedef U Type;
};
// partial specialization
template<class T, int N, class U>
struct Array_rebind<T[N], U>
{
typedef Array_rebind<T,U>::Type Type[N];
};
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-prs
mailing list