https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113246
Bug ID: 113246
Summary: Behavior of std::filesystem::weakly_canonical with
non-existing relative paths
Product: gcc
Version: 13.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: davidepesa at gmail dot com
Target Milestone: ---
I initially reported this as a Boost.Filesystem issue
(https://github.com/boostorg/filesystem/issues/300), but std::filesystem in
libstdc++ has the same behavior.
With -std=c++17, weakly_canonical("foo/bar") returns "foo/bar" when "foo" does
not exist in the current working directory.
Conversely, when at least one leading element of the input path exists, the
returned path is absolute, e.g., weakly_canonical("existing/foo/bar") ==
"/home/existing/foo/bar".
It's not clear to me how to interpret the standard wording
(https://eel.is/c++draft/fs.op.weakly.canonical#1) in this case. It says:
> 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, ...
If there are no leading elements of p that exist, should canonical() be called
with an empty path? or should it not be called at all? (if it's the former,
note that canonical("") currently throws a filesystem_error)