Topic: confusing cast example


Author: Sandra Loosemore <sandra@shore.net>
Date: 2000/05/06
Raw View
Section 5.4 of the standard, on old-style cast notation, contains this
language and example:

  If a conversion can be interpreted in more than one of the ways listed
  above, the interpretation that appears first in the list is used, even
  if a cast resulting from that interpretation is ill-formed.  If a
  conversion can be interpreted in more than one way as a static_cast
  followed by a const_cast, the conversion is ill-formed.  [Example:

  struct A {};
  struct I1 : A {};
  struct I2 : A {};
  struct D : I1, I2 {};

  A *foo (D *p) { return (A *)(p); }  // ill-formed static_cast interpretation

  --end example]

What exactly is this example supposed to illustrate?  My read of
section 5.2.9 is that this conversion cannot be interpreted as a
static_cast at all, according the the formula given in section 5.2.11,
because the declaration "A *t(p);" is not well-formed according to
4.10, and none of the other static_cast cases apply.  So what this
conversion actually does is fall through to the reinterpret_cast case,
right?

-Sandra

---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]