Created on 2003-10-10.00:00:00 last changed 33 months ago
[Voted into WP at April 2005 meeting.]
Proposed Resolution:
Change 11.4 [class.mem] paragraph 2 as follows:
Within the class member-specification, the class is regarded as complete within function bodies, default arguments, exception-specifications, and constructor ctor-initializers (including such things in nested classes).
Rationale: Taken with 9.3.4.6 [dcl.fct] paragraph 6, the exception-specification is the only part of a function declaration/definition in which the class name cannot be used because of its putative incompleteness. There is no justification for singling out exception specifications this way; both in the function body and in a catch clause, the class type will be complete, so there is no harm in allowing the class name to be used in the exception-specification.
I've encountered a C++ program in which a member function wants to declare that it may throw an object of its own class, e.g.:
class Foo { private: int val; public: Foo( int &initval ) { val = initval; }; void throwit() throw(Foo) { throw (*this); }; };
The compiler is complaining that Foo is an incomplete type, and can't be used in the exception specification.
My reading of the standard [basic.types] is inconclusive. Although it does state that the class declaration is considered complete when the closing brace is read, I believe it also intends that the member function declarations should not be semantically validated until the class has been completely declared.
If this isn't allowed, I don't know how else a member function could be declared to throw an object of its own class.
John Spicer: The type is considered complete within function bodies, but not in their declaration (see 11.4 [class.mem] paragraph 2).
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-02-18 07:47:23 | admin | set | messages: + msg6690 |
2008-10-05 00:00:00 | admin | set | status: wp -> cd1 |
2005-10-22 00:00:00 | admin | set | status: dr -> wp |
2005-05-01 00:00:00 | admin | set | messages: + msg1191 |
2005-05-01 00:00:00 | admin | set | status: ready -> dr |
2004-11-07 00:00:00 | admin | set | status: review -> ready |
2004-04-09 00:00:00 | admin | set | status: open -> review |
2003-10-10 00:00:00 | admin | create |