Title
~ios_base() usage valid?
Status
tc1
Section
[ios.base.cons]
Submitter
Jonathan Schilling, Howard Hinnant

Created on 2000-03-13.00:00:00 last changed 171 months ago

Messages

Date: 2010-10-21.18:28:33

Proposed resolution:

Modify 27.4.2.7 paragraph 1 from

Effects: Each ios_base member has an indeterminate value after construction.

to

Effects: Each ios_base member has an indeterminate value after construction. These members must be initialized by calling basic_ios::init. If an ios_base object is destroyed before these initializations have taken place, the behavior is undefined.

Date: 2000-03-13.00:00:00

The pre-conditions for the ios_base destructor are described in 27.4.2.7 paragraph 2:

Effects: Destroys an object of class ios_base. Calls each registered callback pair (fn,index) (27.4.2.6) as (*fn)(erase_event,*this,index) at such time that any ios_base member function called from within fn has well defined results.

But what is not clear is: If no callback functions were ever registered, does it matter whether the ios_base members were ever initialized?

For instance, does this program have defined behavior:

#include <ios>
class D : public std::ios_base { };
int main() { D d; }

It seems that registration of a callback function would surely affect the state of an ios_base. That is, when you register a callback function with an ios_base, the ios_base must record that fact somehow.

But if after construction the ios_base is in an indeterminate state, and that state is not made determinate before the destructor is called, then how would the destructor know if any callbacks had indeed been registered? And if the number of callbacks that had been registered is indeterminate, then is not the behavior of the destructor undefined?

By comparison, the basic_ios class description in 27.4.4.1 paragraph 2 makes it explicit that destruction before initialization results in undefined behavior.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg1894
2000-03-13 00:00:00admincreate