Skip to content

LWG4090 Underspecified use of locale facets for locale-dependent std::format #1893

@jwakely

Description

@jwakely
Member

https://cplusplus.github.io/LWG/issue4090

LWG would like SG16 to look at this issue please

Activity

changed the title [-]LWG 4090. Underspecified use of locale facets for locale-dependent std::format[/-] [+]LWG4090 Underspecified use of locale facets for locale-dependent std::format[/+] on May 26, 2024
tahonermann

tahonermann commented on Nov 18, 2024

@tahonermann
Collaborator

SG16 discussed this issue during its 2024-06-12 meeting. No polls were taken. SG16 will review again in the new year.

tahonermann

tahonermann commented on Jun 11, 2025

@tahonermann
Collaborator

Now that I've finally published a meeting summary for the 2024-06-12 SG16 meeting, I can detail the next steps for resolving this issue.

SG16 concluded that the std::numpunct facet should be used to format integer, floating-point, and bool types and that this matches existing implementation behavior for libc++, libstdc++, and MS STL as exhibited at https://godbolt.org/z/GM6Mzv6vG. This program:

#include <format>
#include <iostream>
#include <locale>

struct test_numpunct : std::numpunct<char> {
  char do_decimal_point() const override {
	return '-';
  }
  char do_thousands_sep() const override {
	return '\'';
  }
  std::string do_grouping() const override {
	return "\1";
  }
  std::string do_truename() const override {
	return "eurt";
  }
  std::string do_falsename() const override {
	return "eslaf";
  }
};

int main() {
  std::locale loc;
  std::cout << std::format(loc, "{:L} {:L} {:L} {:L}\n", 123456, 123.456, true, false);
  loc = std::locale(loc, new test_numpunct);
  std::cout << std::format(loc, "{:L} {:L} {:L} {:L}\n", 123456, 123.456, true, false);
}

produces the following output for all three implementations.

123456 123.456 true false
1'2'3'4'5'6 1'2'3-456 eurt eslaf

Despite implementations doing the right thing, the intended behavior is under specified in the standard and [format.string.std] should be updated accordingly. A proposed resolution is needed to make further progress on this issue. I'll ask SG16 participants for a volunteer to draft wording. Once a PR materializes, I'll have SG16 confirm it matches the intent.

jwakely

jwakely commented on Jun 12, 2025

@jwakely
MemberAuthor

https://godbolt.org/z/PexbszhWs extends the example to show a custom num_put facet which is not used by the std::format calls (but is used when writing to a stream directly after imbuing the stream with the locale). This confirms that implementations use numpunct directly, not via num_put.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    SG16Text processing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jwakely@tahonermann

        Issue actions

          LWG4090 Underspecified use of locale facets for locale-dependent std::format · Issue #1893 · cplusplus/papers