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

381. detection of invalid mbstate_t in codecvt

Section: [locale.codecvt.byname] Status: CD1 Submitter: Martin Sebor Opened: 2002-09-06 Last modified: 2017-02-03

Priority: Not Prioritized

View all other issues in [locale.codecvt.byname].

View all issues with CD1 status.


All but one codecvt member functions that take a state_type argument list as one of their preconditions that the state_type argument have a valid value. However, according to, p6, codecvt::do_unshift() is the only codecvt member that is supposed to return error if the state_type object is invalid.

It seems to me that the treatment of state_type by all codecvt member functions should be the same and the current requirements should be changed. Since the detection of invalid state_type values may be difficult in general or computationally expensive in some specific cases, I propose the following:

Proposed resolution:

Add a new paragraph before, p5, and after the function declaration below

    result do_unshift(stateT& state,
    externT* to, externT* to_limit, externT*& to_next) const;

as follows:

    Requires: (to <= to_end) well defined and true; state initialized,
    if at the beginning of a sequence, or else equal to the result of
    converting the preceding characters in the sequence.

and change the text in Table 54, row 4, the error row, under the heading Meaning, from

    state has invalid value


    an unspecified error has occurred


The intent is that implementations should not be required to detect invalid state values; such a requirement appears nowhere else. An invalid state value is a precondition violation, i.e. undefined behavior. Implementations that do choose to detect invalid state values, or that choose to detect any other kind of error, may return error as an indication.