0

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?

2
  • Could you check the status of the earlier components of the path, namely "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. Commented Sep 27 at 23:00
  • 1
    @JaMiT, thanks for the idea. It appears that "C:\\" is not even an existing directory, while "C:\\Windows\\" already exists. And std::canonical fails for all of them: gcc.godbolt.org/z/qPev761er Commented Sep 28 at 9:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.