Topic: reinterpret_cast paragraph
Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@googlemail.com>
Date: Tue, 10 Nov 2009 14:20:29 CST Raw View
On 9 Nov., 21:59, aegis <ae...@mad.scientist.com> wrote:
> Does section 5.2.10#7 apply to the casting constructor
> (T_1 *)p; where p is of type T_2 *?
> Or does it strictly apply to the reinterpret_cast operator?
There does not exist a casting constructor, your probably
refer to the /explicit type conversion/ from 5.4 [expr.cast],
which is often referred to as "C cast".
I also assume that you refer to the recent working paper
N2960, where we have
"A pointer to an object can be explicitly converted to a pointer
to a different object type. [..]"
This is a direct description of what the reinterpret_cast
operator does, but as of [expr.cast]/4 the "C cast" has -
depending on it's calling context - the semantics of
combinations of const_cast, static_cast, and
reinterpret_cast. If in your example T_1 is int but
T_2 is void, it is a static_cast, but if T_1 is int, but
T_2 is const int, it's a a static_cast followed by a
const_cast. Third, if T_1 is int, but T_2 is double,
it's a reinterpret_cast, etc.
The current wording is not 100% clear for some
situations, see e.g.
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#242
> If it strictly applies to the reinterpret_cast operator,
> where in the standard is the behavior for the
> casting constructor from C described?
I named it loosely as "C cast" but of-course this is just
the symbol from C with backward-compatible meaning
of the C cast operator. In C++ it's meaning is defined
in terms of possible combinations of it's three conversion
operators, as shown above.
HTH & Greetings from Bremen,
Daniel Kr gler
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: James Kanze <james.kanze@gmail.com>
Date: Tue, 10 Nov 2009 14:21:01 CST Raw View
On Nov 9, 8:59 pm, aegis <ae...@mad.scientist.com> wrote:
> Does section 5.2.10#7 apply to the casting constructor
> (T_1 *)p; where p is of type T_2 *?
It depends. *IF* the explicit type conversion (C style cast)
resolves to a reinterpret_cast, then the rules for
reinterpret_cast apply. If it doesn't, then they don't.
> Or does it strictly apply to the reinterpret_cast operator?
It applies to the reinterpret_cast operator.
> If it strictly applies to the reinterpret_cast operator, where
> in the standard is the behavior for the casting constructor
> from C described?
In 5.4. The conversion performed by a C style cast are the
same as the first of the following which would be legal:
a const_cast
a static_cast
a static_cast followed by a const_cast
a reinterpret_cast
a reinterpret_cast followed by a const_cast
, with the reservation that access control is not considered
when considering the legality. So given:
class L {};
class R {};
class D : public L, public R {};
L* pl;
R* pr;
D* pd;
(L*)pl, (L*)pd, (R*)pr, (R*)pd, (D*)pl, (D*)pr and (D*)pl are
static_cast, (L*)pr and (R*)pl are reinterpret_cast.
--
James Kanze
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: CornedBee <wasti.redl@gmx.net>
Date: Tue, 10 Nov 2009 16:59:43 CST Raw View
On Nov 9, 9:59 pm, aegis <ae...@mad.scientist.com> wrote:
> Does section 5.2.10#7 apply to the casting constructor
> (T_1 *)p; where p is of type T_2 *?
> Or does it strictly apply to the reinterpret_cast operator?
>
> If it strictly applies to the reinterpret_cast operator,
> where in the standard is the behavior for the
> casting constructor from C described?
The C-style cast is defined in terms of static_cast, reinterpret_cast
and const_cast, with a few special cases regarding access.
Sebastian
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: aegis <aegis@mad.scientist.com>
Date: Mon, 9 Nov 2009 14:59:52 CST Raw View
Does section 5.2.10#7 apply to the casting constructor
(T_1 *)p; where p is of type T_2 *?
Or does it strictly apply to the reinterpret_cast operator?
If it strictly applies to the reinterpret_cast operator,
where in the standard is the behavior for the
casting constructor from C described?
Thanks.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]