|
Boost : |
From: Darin Adler (darin_at_[hidden])
Date: 1999-11-05 10:38:32
Beman Dawes wrote:
> Issue 3: Issue 1 and 2 interact. The proposed resolution for 2
> doesn't fix 1. The proposed solution for 1 also fixes 2 for the
> example given, but silently slices if the template parameter is
> omitted:
>
> Base& rb = implicit_cast(rd); // slices
>
> Anyone have a resolution that solves all three issues?
It seems that that this is a minor problem compared with issues 1 and 2.
Reasons:
- implicit_cast is not intended to be called without a template
parameter.
- The specific example you give above results in a temporary bound to a
non-const reference; a diagnostic is required from a conforming compiler. My
compiler warns "non-const '&' reference initialized to temporary". The
standard makes more guarantees when the reference is const, so this is a
more troublesome case:
const Base& rb = implicit_cast(rd);
- Valentin's version copies a Derived, while the old implicit_cast
slices off a Base. Slicing can still occur, but only if the object's type is
a subclass of Derived.
- Slicing will only happen if Derived is copyable.
Of course, if someone can make a version of implicit_cast that won't compile
in this case, that's even better, but I think it's unlikely.
-- Darin
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk