Based on cppreference, I was under impression that std::canonical and std::weakly_canonical return the input path if it is an absolute directory path to existing directory that has no dot, dot-dot elements or symbolic links. But in certain cases I see that the call results in an error.
This program:
#include <filesystem>
#include <iostream>
int main() {
std::error_code ec;
auto dir = std::filesystem::temp_directory_path( ec );
std::cout << dir.string() << "\n";
std::cout << exists( dir, ec ) << is_directory( dir, ec ) << "\n";
std::cout << weakly_canonical( dir, ec ) << "\n";
std::cout << ec.message() << "\n";
}
being executed on godbolt prints
C:\Windows\SystemTemp\
11
""
Access is denied.
Is the implementation correct here?
"C:\\"and"C:\\Windows\\"? The check for existence probably begins at the start and builds up what exists, not at the end and removes what does not exist."C:\\"is not even an existing directory, while"C:\\Windows\\"already exists. Andstd::canonicalfails for all of them: gcc.godbolt.org/z/qPev761er