This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/11765] typecast vs. constructor ambiguity


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);
---------------------------------------------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]