This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of TC1 status.

220. ~ios_base() usage valid?

Section: [ios.base.cons] Status: TC1 Submitter: Jonathan Schilling, Howard Hinnant Opened: 2000-03-13 Last modified: 2017-02-03

Priority: Not Prioritized

View all issues with TC1 status.


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

Effects: Destroys an object of class ios_base. Calls each registered callback pair (fn,index) ( 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 paragraph 2 makes it explicit that destruction before initialization results in undefined behavior.

Proposed resolution:

Modify paragraph 1 from

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


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.