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.

3098. Misleading example for filesystem::path::filename()

Section: 29.12.6.5.9 [fs.path.decompose] Status: New Submitter: Jonathan Wakely Opened: 2018-04-06 Last modified: 2020-09-06

Priority: 3

View all other issues in [fs.path.decompose].

View all issues with New status.

Discussion:

The example in [fs.path.decompose] p7 includes:

path("//host").filename();  // yields ""

This result isn't guaranteed, it depends whether the implementation interprets "//host" as a root-name or as a root-directory (with a redundant directory-separator) followed by the filename "host".

The example should make it clear that this interpretation is allowed.

Previous resolution [SUPERSEDED]:

This wording is relative to N4727.

  1. Edit 29.12.6.5.9 [fs.path.decompose] as indicated:

    path filename() const;
    

    -6- Returns: relative_path().empty() ? path() : *--end().

    [Example:

    path("/foo/bar.txt").filename(); // yields "bar.txt"
    path("/foo/bar").filename();     // yields "bar"
    path("/foo/bar/").filename();    // yields ""
    path("/").filename();            // yields ""
    path("//host").filename();       // yields "" or "host"
    path(".").filename();            // yields "."
    path("..").filename();           // yields ".."
    

    — end example]

[2018-04-10, Jonathan comments and provides revised wording]

Based on the reflector discussion I'd like to change the P/R to Billy's suggestion of simply removing that line from the example.

[2018-06-18 after reflector discussion]

Priority set to 3

Proposed resolution:

This wording is relative to N4741.

  1. Edit 29.12.6.5.9 [fs.path.decompose] as indicated:

    path filename() const;
    

    -6- Returns: relative_path().empty() ? path() : *--end().

    [Example:

    path("/foo/bar.txt").filename(); // yields "bar.txt"
    path("/foo/bar").filename();     // yields "bar"
    path("/foo/bar/").filename();    // yields ""
    path("/").filename();            // yields ""
    path("//host").filename();       // yields ""
    path(".").filename();            // yields "."
    path("..").filename();           // yields ".."
    

    — end example]