egcs-980517 bug report

Martin von Loewis martin@mira.isdn.cs.tu-berlin.de
Fri May 22 00:44:00 GMT 1998


> I think the following C++ code should not compile.
> 
> // should fail, since class C is unknown
> 
> class C;
> C * c;
> 
> int main(void)
> {
> 	void (C::*pf) (int);
> 	((c)->*pf)(1);	// here.
> 	return 0;
> }

I believe this is valid C++, except that the behaviour is unspecified
as pf is not initialized.

[basic.def.odr]/4 defines the conditions under which a class must be
complete (in a non-normative note, summarizing other clauses):

-- an object of type T is defined (3.1, 5.3.4), or 
-- an lvalue­to­rvalue conversion is applied to an lvalue referring to
   an object of type T (4.1), or
-- an expression is converted (either implicitly or explicitly) to
   type T (clause 4, 5.2.3, 5.2.7, 5.2.9, 5.4), or
-- an expression that is not a null pointer constant, and has type
   other 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
-- a class member access operator is applied to an expression of type
   T (5.2.5), or
-- the typeid operator (5.2.8) or the sizeof operator (5.3.3) is
   applied to an operand of type T, or
-- a function with a return type or argument type of type T is defined
   (3.1) or called (5.2.2), or
-- an lvalue of type T is assigned to (5.17).

Since pointer-to-member operators are not listed, your example doesn't
show a bug in g++.

Regards,
Martin



More information about the Gcc-bugs mailing list