Topic: Defect Report: Clarification on casting between incomplete class types
Author: Me <anti_spam_email2003@yahoo.com>
Date: Thu, 19 May 2005 15:10:43 +0000 (UTC) Raw View
[ Note: Forwarded to C++ Committee. -sdc ]
5.4/6 - The operand of a cast using the cast notation can be an rvalue
of type "pointer to incomplete class type". The destination type of a
cast using the cast notation can be "pointer to incomplete class type".
In such cases, even if there is a inheritance relationship between the
source and destination classes, whether the static_cast or
reinterpret_cast interpretation is used is unspecified.
The wording seems to allow the following:
1. casting to from void pointer to incomplete type
struct A;
struct B;
void *v;
A *a = (A*)v; // allowed to choose reinterpret_cast
2. variant application of static or reinterpret casting
B *b = (B*)a; // compiler can choose static_cast here
A *aa = (A*)b; // compiler can choose reinterpret_cast here
assert(aa == a); // might not hold
3. ability to somehow choose static_cast
It's not entirely clear how a compiler can choose static_cast as 5.4/6
seems to allow. I believe the intent of 5.4/6 is to force the use of
reinterpret_cast when either are incomplete class types and static_cast
iff the compiler knows both types and there is a non-ambiguous
hierarchy-traversal between that cast (or maybe not, core issue 242
talks about this). I cannot see any other interpretation because it
isn't intuitive, every compiler I've tried agrees with me, and neither
standard pointer conversions (4.10/3) nor static_cast (5.2.9/5) talk
about incomplete class types. If the committee agrees with me, I would
like to see 4.10/3 and 5.2.9/5 explicitly disallow incomplete class
types and the wording of 5.4/6 changed to not allow any other
interpretation.
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]