c++/99: [2003-03-26] Bug in type in error message.
Christian Ehrhardt
ehrhardt@mathematik.uni-ulm.de
Tue May 6 13:06:00 GMT 2003
Here's a further reduced testcase, along with some more analysis:
template<typename S> class X {};
template<typename Q> int f(X<int>, X<Q>);
template<typename B> int f(X<B>, X<int>);
int main(void) {
return f(X<int>(), X<int>());
}
If compiled this will output the following error message (note Q instead
of B in the last line):
99-3.cc: In function `int main()':
99-3.cc:6: call of overloaded `f(X<int>, X<int>)' is ambiguous
99-3.cc:2: candidates are: int f(X<int>, X<Q>) [with Q = int]
99-3.cc:3: int f(X<Q>, X<int>) [with B = int]
Analysis: When instantiating X<Q> a typedef like construct is
created an added the list of instantiations of X. Should we
ever ancounter X<Q> again, this type will be reused an no new instantiation
is created. We also note along with the type that the template parameter
S is bound to the outer template parameter Q. The relevant code for this
is in pt.c:lookup_template_class.
Problem: When we need to find a type for X<B> in a completly different
outer template we walk the list of instantiations again (line 4322)
and come accross the instance of X<Q>. At this point gcc (wrongly)
decides that the Q in X<Q> and B are the same template parameters and
reuses X<Q> instead of creating a new type. This can happen because
there is no check if we're still in the same outer template. There are
only checks if TEMPLATE_TYPE_IDX and TEMPLATE_TYPE_LEVEL match.
However, the context of TEMPLATE_TYPE_DECLs should be compared somehow
as well.
regards Christian
--
THAT'S ALL FOLKS!
More information about the Gcc-bugs
mailing list