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

### 417. what does `ctype::do_widen()` return on failure

Section: 30.4.2.2.3 [locale.ctype.virtuals] Status: NAD Submitter: Martin Sebor Opened: 2003-09-18 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [locale.ctype.virtuals].

View all issues with NAD status.

Discussion:

The Effects and Returns clauses of the `do_widen()` member function of the `ctype` facet fail to specify the behavior of the function on failure. That the function may not be able to simply cast the narrow character argument to the type of the result since doing so may yield the wrong value for some `wchar_t` encodings. Popular implementations of `ctype<wchar_t>` that use `mbtowc()` and UTF-8 as the native encoding (e.g., GNU glibc) will fail when the argument's MSB is set. There is no way for the the rest of locale and iostream to reliably detect this failure.

[Kona: This is a real problem. Widening can fail. It's unclear what the solution should be. Returning `WEOF` works for the `wchar_t` specialization, but not in general. One option might be to add a default, like narrow. But that's an incompatible change. Using traits::eof might seem like a good idea, but facets don't have access to traits (a recurring problem). We could have widen throw an exception, but that's a scary option; existing library components aren't written with the assumption that widen can throw.]

[ 2009-07 Frankfurt ]

> NAD. The behavior is specified for all of the facets that an implementation is required to provide, for the basic character set.

Proposed resolution: