filesystem::weakly_canonical
Section: 31.12.13.40 [fs.op.weakly.canonical] Status: C++23 Submitter: US Opened: 2022-11-08 Last modified: 2023-11-22
Priority: Not Prioritized
View all other issues in [fs.op.weakly.canonical].
View all issues with C++23 status.
Discussion:
This addresses NB comment US-60-125 (31.12.13.40 [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:
path
objects to cache some kind of
flag that indicates they are in a normalized form, which would be checked in
weakly_canonical
to avoid normalizing again. This is the interpretation
assumed by the NB comment, which correctly notes that such caching would be
unreliable.
"/a/b/c"
by incrementally building up canonicalized
components, if the entire path exists then the result will already have been
normalized and should not be normalized again explicitly.
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.
Modify 31.12.13.40 [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)
orstatus(p, ec)
, respectively, to determine existence, return a path composed byoperator/=
from the result of callingcanonical()
with a path argument composed of the leading elements ofp
that exist, if any, followed by the elements ofp
that do not exist, if any. For the first form,canonical()
is called without anerror_code
argument. For the second form,canonical()
is called withec
as anerror_code
argument, andpath()
is returned at the first error occurrence, if any.-2- Postconditions: The returned path is in normal form (31.12.6.2 [fs.path.generic]).
-3- Returns:
p
with symlinks resolved and the result normalized (31.12.6.2 [fs.path.generic]).-4- Throws: As specified in 31.12.5 [fs.err.report].
-5- Remarks: Implementations should avoid unnecessary normalization such as whencanonical
has already been called on the entirety ofp
.