egcs-1.0.1 confused by explicit cast
Richard Hadsell
hadsell@blueskystudios.com
Mon Jan 26 11:54:00 GMT 1998
Jason Merrill wrote:
>
> 5.2.9 Static cast [expr.static.cast]
>
> 2 An expression e can be explicitly converted to a type T using a
> static_cast of the form static_cast<T>(e) if the declaration T t(e);"
> is well-formed, for some invented temporary variable t (_dcl.init_).
> The effect of such an explicit conversion is the same as performing
> the declaration and initialization and then using the temporary vari-
> able as the result of the conversion.
>
> Since the above declaration is a direct-initialization, and so the
> candidates are the constructors of T, the same is true of a cast. The cast
> notation does not have different semantics.
(a) I'm not using "static_cast<T>(e)". I am using 5.4 -- "Explicit type
conversion (cast notation)." I think you have missed 5.4 paragraph 4 --
"Any type conversion not mentioned below and not explicitly defined by
the user (_class.conv_) is ill-formed." The reference "_class.conv_"
points to 12.3. Clearly, explicit type conversions can be defined by
the user, as I did, and they are meant to be used when one tries to
convert to that type.
(b) The statement "a = b;" works, and it requires an implicit
conversion. Since there are no standard conversions available, it must
use a user-defined conversion. Only one user-defined conversion is
allowed, so it must be the conversion function. There is no constructor
that will make this conversion.
(c) It makes no sense to say that "a = b;" does the right thing, but "a
= (A) b;" can't figure out what to do. I am sure the standards
committee could not mean this. For example, Josee Lajoie described type
conversions in C++ Report, 7:3 (3-4/95), pp. 40-46. Look at the
"User-defined Conversions" section on p. 44. I can't believe that the
standard has changed in something this basic.
(d) There are a number of compilers that have no trouble with this --
SGI's CC 7.1, both old and new compilers; KAI's KCC 3.2; gcc version
2.7.2.1; an old cfront CC on HP-UX.
Please take this seriously, so that I can take egcs seriously.
--
Dick Hadsell 914-381-8400 Fax: 914-381-9790
Reply-to: hadsell@blueskystudios.com
Blue Sky | VIFX http://www.blueskystudios.com
1 South Road, Harrison, NY 10528
More information about the Gcc-bugs
mailing list