Re: gcc 4.1.2 bug?
Tarjan Denes wrote:
We've encountered a problem using g++ compiler version 4.1.2 (that was the
latest we downloaded). Seems like a bug, but we're not sure. We didn't
find any related problem in the gcc mailing list.
Here is a simplified code that causes the problem:
template<typename T, int v, template<typename,int> class RD =
record_descriptor> class TableRecord {
public:
TableRecord()
{
RD<T, v> d;
d();
}
};
So the expectation is that is RD<T,v> when instantiated with
Attr::i_record_descriptor class template (defined below) will use a
specialization whenever T is the same type as Attr's own type
parameter.
The problem with this expectation, as I see it, is this: how can the
compiler tell what Attr's type parameter is when instantiating just the
Table record class template above? There is no way of recovering RD's
enclosing class template (or even to tell whether it has one) from the
template template parameter used to instantiate RD - and being able to
recover Attr's type parameter is necessary in order to match the
i_record_descriptor specialization. So without any way of testing
whether the specialization is a match, the compiler instantiates RD
with its general class template and not the provided specialization.
template<typename A> class Attr
{
public:
template <typename T, int v> class i_record_descriptor
{
public:
void operator()()
{
printf("Inner template\n");
}
};
template <int v> class i_record_descriptor<A, v>
{
public:
void operator()()
{
printf("Inner spec template\n");
}
};
Attr()
{
TableRecord<A, 1, i_record_descriptor> tr;
}
};
I would suggest fixing the problem by not having specializations of an
inner template be dependent on the type parameters of an outer
template. And in fact, simplifying this set of template classes overall
- would be my other suggestion.
Greg
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]