3822. Avoiding normalization in filesystem::weakly_canonical

Section: [fs.op.weakly.canonical] Status: C++23 Submitter: US Opened: 2022-11-08 Last modified: 2023-11-22 15:47:43 UTC

Priority: Not Prioritized

View all other issues in [fs.op.weakly.canonical].

View all issues with C++23 status.


This addresses NB comment US-60-125 ( [fs.op.weakly.canonical] Avoiding normalization)

NB comment: "Implementations cannot avoid normalization because arbitrary file system changes may have occurred since any previous call. Proposed change: Remove the paragraph."

[Kona 2022-11-07; LWG review]

Discussion revolved around two different interpretations of the Remarks:

For the first interpretation, the recommendation is a bad recommendation and should be removed as suggested by the comment. For the second interpretation, we don't need to give hints to implementors about not doing unnecessary work; they already know they shouldn't do that. Either way, it should go.

[Kona 2022-11-09; Move to Immediate]

[2022-11-12 Approved at November 2022 meeting in Kona. Status changed: Immediate → WP.]

Proposed resolution:

This wording is relative to N4917.

  1. Modify [fs.op.weakly.canonical] as indicated:

    path filesystem::weakly_canonical(const path& p);
    path filesystem::weakly_canonical(const path& p, error_code& ec);

    -1- Effects: Using status(p) or status(p, ec), respectively, to determine existence, return a path composed by operator/= from the result of calling canonical() with a path argument composed of the leading elements of p that exist, if any, followed by the elements of p that do not exist, if any. For the first form, canonical() is called without an error_code argument. For the second form, canonical() is called with ec as an error_code argument, and path() is returned at the first error occurrence, if any.

    -2- Postconditions: The returned path is in normal form ( [fs.path.generic]).

    -3- Returns: p with symlinks resolved and the result normalized ( [fs.path.generic]).

    -4- Throws: As specified in 31.12.5 [fs.err.report].

    -5- Remarks: Implementations should avoid unnecessary normalization such as when canonical has already been called on the entirety of p.