microsoft / microsoft/STL

`<filesystem>`: `exists` returns true for `[file-path]/.`

Open
#5,748 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug filesystem
Dominant language
C++
Stars
11.2k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

I suspect that in the following code, exists("test/.") should return false, as the path should refer to directory only.

(I haven't looked into the standard, but gcc and clangs reports assertion failure, and cppreference says v.)

Image
#include<fstream>
#include<filesystem>
#include<cassert>

int main()
{
    using namespace std::filesystem;

    std::ofstream("test") << "test";
    // As expected:
    assert(exists("test"));
    assert(is_regular_file("test"));
    assert(!exists("test/"));

    // But what about these? (Currently they will pass the assertion...)
    assert(exists("test/."));
    assert(is_regular_file("test/."));
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided C++ reproducer and verify the standard’s expected behavior for paths ending in /.. Trace the std::filesystem::exists and is_regular_file entry points, then compare their results with the expected directory-only semantics. Done means the behavior is resolved and the shown case has regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.