Topic: incomplete classes and conversions


Author: scott douglass <sdouglass%_%junk@_.arm.com>
Date: 1999/04/15
Raw View
Hello,

Does the standard have anything to say about incomplete classes and
conversions?  For example:

struct C;
struct A { A(const C &); };
struct B;

void f(const A&);
void f(const B&);

void g(C& c) { f(c); }  // #8


struct B { };
struct C : B {};

void g2(C& c) { f(c); }  // means f(static_cast<B&>(c))

At the line marked #8 we don't know if 'c' can be converted to 'const B &=
' or
not because 'B' is incomplete.  I guess common sense tells one that incom=
plete
classes don't have conversions, but I hate to rely on common sense when t=
he
standard is involved.

Does the standard say the possibility must be ignored?  Does it say that
incomplete classes can't be used in this way?

The closest I've found so far is a (non-normative) note in 3.2:

[Note: the rules for declarations and expressions describe in which conte=
xts
complete class types are required. A class type T must be complete if:=20

  =97 an object of type T is defined (3.1, 5.3.4), or=20
  =97 an lvalue-to-rvalue conversion is applied to an lvalue referring to=
 an
object of type T (4.1), or=20
  =97 an expression is converted (either implicitly or explicitly) to typ=
e T
(clause 4, 5.2.3, 5.2.7, 5.2.9, 5.4), or=20
  =97 an expression that is not a null pointer constant, and has type oth=
er than
void *, is converted to the type pointer to T or reference to T using an
implicit conversion (clause 4), a dynamic_cast (5.2.7) or a static_cast (=
5.2.9),
or=20
  =97 a class member access operator is applied to an expression of type =
T
(5.2.5), or=20
  =97 the typeid operator (5.2.8) or the sizeof operator (5.3.3) is appli=
ed to an
operand of type T, or=20
  =97 a function with a return type or argument type of type T is defined=
 (3.1) or
called (5.2.2), or=20
  =97 an lvalue of type T is assigned to (5.17). ]

Which doesn't mention overload resolution at all.

Should a "good" compiler warn in this case? e.g.

line #8: Warning: 'class B' is incomplete, no conversions considered
---
[ 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              ]