Title
import std; should guarantee initialization of standard iostreams objects
Status
c++23
Section
[iostream.objects.overview]
Submitter
Tim Song

Created on 2023-02-09.00:00:00 last changed 5 months ago

Messages

Date: 2023-02-13.11:31:32

Proposed resolution:

This wording is relative to n4928.

  1. Modify [iostream.objects.overview]p5 as indicated:

    -5- The results of including <iostream> in a translation unit shall be as if <iostream> defined an instance of ios_base::Init with static storage duration. Each C++ library module ([std.modules]) in a hosted implementation shall behave as if it contains an interface unit that defines an unexported ios_base::Init variable with ordered initialization ([basic.start.dynamic]).

    [Note ?: As a result, the definition of that variable is appearance-ordered before any declaration following the point of importation of a C++ library module. Whether such a definition exists is unobservable by a program that does not reference any of the standard iostream objects. — end note]

Date: 2023-02-13.00:00:00

[ 2023-02-13 Approved at February 2023 meeting in Issaquah. Status changed: Immediate → WP. ]

Date: 2023-02-10.09:41:49

[ Issaquah 2023-02-09; LWG ]

Move to Immediate for C++23

Date: 2023-02-09.00:00:00

[ 2023-02-09 Tim updates wording following LWG discussion ]

Date: 2023-02-09.00:00:00

In the old world, #include <iostream> behaves as if it defined a static-storage-duration ios_base::Init object, which causes the standard iostreams objects to be initialized (if necessary) on startup and flushed on shutdown.

But we don't include headers with import std;, so we need separate wording to provide this guarantee. The proposed resolution below was adapted from a suggestion by Mathias Stearn on the reflector.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2023-02-13 11:31:32adminsetmessages: + msg13403
2023-02-13 11:31:32adminsetstatus: immediate -> wp
2023-02-10 09:41:49adminsetmessages: + msg13331
2023-02-10 09:41:49adminsetstatus: new -> immediate
2023-02-10 00:11:33adminsetmessages: + msg13319
2023-02-09 18:13:52adminsetmessages: + msg13314
2023-02-09 00:00:00admincreate