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

### 3673. §[locale.cons] Ambiguous argument in Throws for locale+name+category constructor

Section: 30.3.1.3 [locale.cons] Status: New Submitter: Hubert Tong Opened: 2022-02-12 Last modified: 2022-11-01

Priority: 3

View other active issues in [locale.cons].

View all other issues in [locale.cons].

View all issues with New status.

Discussion:

>     locale(const locale& other, const char* std_name, category);

has

> Throws: `runtime_error` if the argument is not valid, or is null.

There being three arguments, the statement is rather problematic. It looks like a copy/paste from

>     explicit locale(const char* std_name);

The conclusion, assuming that "the argument" is also `std_name` in the problem case, seems to be that the statement should be changed to read:

> Throws: `runtime_error` if `std_name` is not valid, or is null.

However there is implementation divergence over whether or not values for the category argument not explicitly described as valid by 30.3.1.2.1 [locale.category] result in `runtime_error`.

libc++ does not throw. libstdc++ does.

Code:

>     #include <locale>
>     #include <stdio.h>
>     #include <exception>
>     int main(void) {
>       std::locale Generic("C");
>       try {
>         std::locale Abomination(Generic, Generic, 0x7fff'ffff);
>       } catch (std::runtime_error&) {
>         fprintf(stderr, "Threw\n");
>       }
>     }

Compiler Explorer link.

[2022-03-04; Reflector poll]

Set priority to 3 after reflector poll.

[2022-11-01; Jonathan comments]

The proposed resolution of 2295 would resolve this too.

The implementation divergence is not a problem. 30.3.1.2.1 [locale.category] p2 makes invalid `category` values undefined, so silently ignoring them or throwing exceptions are both valid.

Proposed resolution:

> Preconditions: The `category` argument is a valid value 30.3.1.2.1 [locale.category].

> Throws: `runtime_error` if the argument `std_name` is not valid, or is null.