gcc 3.3.3 bug(?): "ambiguous class template instantiation"
david
d.obermann@callassoftware.com
Wed May 12 23:00:00 GMT 2004
Hallo,
The following code does not compile with gcc 3.3.3
but compiles fine with comeau.
Has anybody a fix or can help?
David
-------------------
#include <list>
#include <string>
template< typename TTarget, class TSource >
struct test;
template< typename TTarget, typename TCh, class TTr, class TAl >
struct test< TTarget, std::basic_string<TCh,TTr,TAl> > {
static TTarget f()
{
return TTarget();
}
};
template< typename TTarget, class TString, class TAl, template<class,class>
class TCont >
struct test< TTarget, TCont<TString,TAl> > {
static TTarget f()
{
return TTarget();
}
};
template< typename TTarget, class TSource >
TTarget do_test(const TSource&)
{
return test<TTarget,TSource>::f();
}
int main()
{
std::string s;
std::list<std::string> l;
int i1 = do_test<int>(s);
int i2 = do_test<int>(l);
return i1+i2;
}
---------------------------
The gcc error is:
test.cpp: In function `TTarget do_test(const TSource&) [with TTarget = int,
TSource = std::string]':
test.cpp:34: instantiated from here
test.cpp:27: error: ambiguous class template instantiation for `struct
test<int, std::string>'
test.cpp:17: error: candidates are: struct test<TTarget, TCont<TString, TAl>
>
test.cpp:9: error: struct test<TTarget,
std::basic_string<TCh,
TTr, TAl> >
test.cpp:27: error: incomplete type 'test<int, std::string>' cannot be used
to
name a scope
More information about the Gcc-bugs
mailing list