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

3083. What should ios::iword(-1) do?

Section: 28.5.3.5 [ios.base.storage] Status: WP Submitter: Jonathan Wakely Opened: 2018-03-16 Last modified: 2018-06-12

Priority: 0

View all other issues in [ios.base.storage].

View all issues with WP status.

Discussion:

Is calling iword and pword with a negative argument undefined, or should it cause a failure condition (and return a valid reference)? What about INT_MAX? What about 0?

Using arbitrary indices isn't safe, because the implementation could be already using them for something else. Some replies on the reflector suggested the only reliable argument is one obtained from ios_base::xalloc(). Others pointed out that the iwords and pwords could be stored in sparse arrays, so that any value from INT_MIN to INT_MAX could be a valid key (which might require the implementation to use keys outside that range for its own entries in the arrays).

If it's undefined we should add a Requires element to the spec. If invalid indices are supposed to cause a failure we need to define which indices are invalid (and ensure that's something the implementation can check), and specify that it causes a failure.

[ 2018-03-27 Moved to Tentatively Ready after 5 positive votes on c++std-lib. ]

[2018-06 Rapperswil: Adopted]

Proposed resolution:

This wording is relative to N4727.

  1. Edit 28.5.3.5 [ios.base.storage] as indicated:

    long& iword(int idx);
    

    -?- Requires: idx is a value obtained by a call to xalloc.

    -3- Effects: If iarray is a null pointer, […]

    […]

    void*& pword(int idx);
    

    -?- Requires: idx is a value obtained by a call to xalloc.

    -5- Effects: If iarray is a null pointer, […]

    […]