§[locale.cons] Ambiguous argument in Throws for locale+name+category constructor
Hubert Tong

Created on 2022-02-12.00:00:00 last changed 11 months ago


Date: 2023-03-22.13:19:33

Proposed resolution:

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

Throws: runtime_error if the argumentstd_name is not valid, or is null.

Date: 2023-03-22.00:00:00

[ 2023-03-22 LWG 2295 was approved in Issaquah. Status changed: New → Resolved. ]

Date: 2022-11-15.00:00:00

[ 2022-11-01; Jonathan comments ]

The proposed resolution of 2295 would resolve this too.

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

Date: 2022-03-15.00:00:00

[ 2022-03-04; Reflector poll ]

Set priority to 3 after reflector poll.

Date: 2022-02-12.00:00:00
locale(const locale& other, const char* std_name, category);


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 [locale.category] result in runtime_error.

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


#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.

Date User Action Args
2023-03-22 13:19:33adminsetmessages: + msg13463
2023-03-22 13:19:33adminsetstatus: new -> resolved
2022-11-01 15:05:20adminsetmessages: + msg12904
2022-11-01 15:05:20adminsetmessages: + msg12903
2022-03-04 14:33:52adminsetmessages: + msg12396
2022-02-12 00:00:00admincreate