This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/3708: [2003-01-02] static_cast between classes finds ambiguous base conversion
- From: "Giovanni Bajo" <giovannibajo at libero dot it>
- To: <p dot hornby at ned dot dem dot csiro dot au>,<gcc-gnats at gcc dot gnu dot org>,<gcc-bugs at gcc dot gnu dot org>,<nobody at gcc dot gnu dot org>,<gcc-prs at gcc dot gnu dot org>
- Cc: <nathan at gcc dot gnu dot org>
- Date: Wed, 30 Apr 2003 23:07:22 +0200
- Subject: Re: c++/3708: [2003-01-02] static_cast between classes finds ambiguous base conversion
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=3708
I think there is nothing wrong with this. Nathan's epurated code (for
reference) is:
-----------------------------------------
class Foo
{
public:
Foo() {}
Foo(int) {}
};
class B
{
public:
B() {}
template <class T>
operator T () { return T (); }
};
class D : public B
{
public:
D () {}
operator Foo () { return Foo (); };
};
int main()
{
D d;
static_cast <Foo> (d);
return 0;
}
-----------------------------------------
pr3708.cpp: In function `int main()':
pr3708.cpp:39: error: call of overloaded `Foo(D&)' is ambiguous
pr3708.cpp:4: note: candidates are: Foo::Foo(const Foo&)
pr3708.cpp:7: note: Foo::Foo(int)
It makes sense to me, because there are two ways the compiler can perform
the conversion:
1) using D::operator Foo(), and then calling the implicit copy constructor
Foo::Foo(const Foo&)
2) using template <class T> B::operator T(), specialized as B::operator
int(), and then calling the constructor Foo::Foo(int)
The two ways look both perfectly feasable to me, so I think this is not a
bug. As a further confirmation, Comeau rejects the code in the same way.
If no language lawyer objects, I will close this PR.
Giovanni Bajo