c++/4337: [2003-01-01]c++ ignores cast operator
Mon May 5 01:32:00 GMT 2003
Synopsis: [2003-01-01]c++ ignores cast operator
State-Changed-When: Mon May 5 01:14:02 2003
Not a bug. "a1 = (A1)a2" is a type conversion in cast
notation (Â§5.4). "a1 = const_cast<A1>(a2)" is
ill-formed, but "a1 = static_cast<A1>(a2)" is well-formed,
because "a1 = A1(a2)" is well-formed (this is the exact
condition specified by Â§5.2.9p2). Thus, for Â§5.4p5, the
cast notation is equivalent to the static_cast notation.
The static_cast notation is then equivalent to
"a1 = A1(a2)", which upcasts a2 to const A& implicitally,
and then invokes A1(const A&).
G++ behaves exactly as the standard prescribes, and all
the other compilers I have agree.
If you need to force the use of the custom conversion
operator, you can still do it using the syntax
"a1 = a2.operator A1()".
More information about the Gcc-bugs