Title
The `system_encoded_string()` and `generic_system_encoded_string()` member functions of `std::filesystem::path` are misnamed
Status
new
Section
[fs.class.path.general][fs.path.type.cvt] [fs.path.native.obs][fs.path.generic.obs] [depr.fs.path.obs]
Submitter
Tom Honermann

Created on 2026-01-11.00:00:00 last changed 3 days ago

Messages

Date: 2026-01-18.13:38:49

Proposed resolution:

This wording is relative to N5032.

  1. Modify [fs.class.path.general], class path synopsis, as indicated:

    namespace std::filesystem {
      class path {
      public:
        […]
        // [fs.path.native.obs], native format observers
        […]
        std::string display_string() const;
        std::string systemnative_encoded_string() const;
        std::wstring wstring() const;
        […]
        
        // [fs.path.generic.obs], generic format observers
        […]
        std::string generic_display_string() const;
        std::string generic_systemnative_encoded_string() const;
        std::wstring generic_wstring() const;
        […]
      };
    }
    
  2. Modify [fs.path.type.cvt] as indicated:

    -2- For member function arguments that take character sequences representing paths and for member functions returning strings, value type and encoding conversion is performed if the value type of the argument or return value differs from `path::value_type`. For the argument or return value, the method of conversion and the encoding to be converted to is determined by its value type:

    • (2.1) — `char`: The encoding is the native ordinary encoding. The method of conversion, if any, is operating system dependent.

      [Note 1: For POSIX-based operating systems `path::value_type` is `char` so no conversion from `char` value type arguments or to `char` value type return values is performed. For Windows-based operating systems, the native ordinary encoding is determined by calling a Windows API functionthe current locale encoding and the Windows `AreFileApisANSI` function. — end note]

      […]

    • (2.2) — […]

    • […]

  3. Modify [fs.path.native.obs] as indicated:

    std::string systemnative_encoded_string() const;
    std::wstring wstring() const;
    std::u8string u8string() const;
    std::u16string u16string() const;
    std::u32string u32string() const;
    

    -7- Returns: `native()`.

    -8- Remarks: Conversion, if any, is performed as specified by [fs.path.cvt].

  4. Modify [fs.path.generic.obs] as indicated:

    std::string generic_systemnative_encoded_string() const;
    std::wstring generic_wstring() const;
    std::u8string generic_u8string() const;
    std::u16string generic_u16string() const;
    std::u32string generic_u32string() const;
    

    -5- Returns: The pathname in the generic format.

    -6- Remarks: Conversion, if any, is specified by [fs.path.cvt].

  5. Modify [depr.fs.path.obs] as indicated:

    std::string string() const;
    

    -2- Returns: systemnative_encoded_string().

    std::string generic_string() const;
    

    -3- Returns: generic_systemnative_encoded_string().

Date: 2026-01-11.00:00:00

Addresses US 189-304

The `system_encoded_string()` and `generic_system_encoded_string()` member functions of `std::filesystem::path` are misnamed. These functions were added as renamed versions of `string()` and `generic_string()` respectively by P2319R5 ("Prevent path presentation problems"). The original function names are now deprecated.

The C++ standard does not define "system encoding" and casual use of such a term is at best ambiguous. In common language, one might expect the "system encoding" to correspond to the environment encoding (for which `std::text_encoding::environment()` provides a definition) or the encoding of the current locale. However, neither of these encodings corresponds to the encoding these functions are expected to use. [fs.path.type.cvt] defines "native encoding" and, for `char`-based filesystem paths, states (in a note) that "For Windows-based operating systems, the native ordinary encoding is determined by calling a Windows API function." It is not specified which Windows API function is consulted, but existing implementations call `AreFileApisANSI()` to choose between the Active Code Page (`CP_ACP`) and the OEM Code Page (`CP_OEMCP`). Microsoft's implementation also checks for a thread-local locale and, if the locale encoding is UTF-8, prefers that (`CP_UTF8`) over either of the other two.

History
Date User Action Args
2026-01-18 13:38:49adminsetmessages: + msg15893
2026-01-11 00:00:00admincreate