This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/11765] typecast vs. constructor ambiguity
- From: "reichelt at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 4 Aug 2003 23:55:23 -0000
- Subject: [Bug c++/11765] typecast vs. constructor ambiguity
- References: <20030801174818.11765.hovik@melikyan.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11765
------- Additional Comments From reichelt at gcc dot gnu dot org 2003-08-04 23:55 -------
I'm not sure if this is really a bug.
The error message actually makes sense to me:
gccbug.cxx:27: error: call of overloaded `ClassOne(ClassTwo&)' is ambiguous
In line 27 we actually have "ClassOne(a)", where "a" is of type "ClassTwo".
And there are really two ways to construct "ClassOne" from "ClassTwo":
1) Apply "ClassTwo::operator ClassOne()"
2) Apply "ClassTwo::operator int()" and then "ClassOne::ClassOne(int)".
The question is: Should 1) be preferred over 2)?
You say "yes", gcc says "no" (since gcc 2.95.x).
Unfortunately, I don't know the correct answer.
(Btw, Intel 7.1 also rejects the code with a similar error message.)
Finally, here's a shorter testcase:
---------------------------------------------------------
struct X
{
X(int) {}
};
struct Y
{
operator int() { return 0; }
operator X() { return X(0); }
};
Y y;
X x(y);
---------------------------------------------------------