https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94900

            Bug ID: 94900
           Summary: filesystem recursive_directory_iterator incorrectly
                    skips entries in case directories can not be read
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tonvandenheuvel at gmail dot com
  Target Milestone: ---

Suppose we have a subdirectory `x` with two other subdirectories `a` and `b`,
both unreadable for the current user:

  $ mkdir -p x/a x/b && chmod 000 x/a x/b

Then, the following program will only print one of the two directories:

  #include <filesystem>
  #include <iostream>

  namespace sfs = std::filesystem;

  int main(int argc, char** argv)
  {
    std::error_code ec;
    for (sfs::recursive_directory_iterator it{"x"}; it !=
sfs::recursive_directory_iterator();
         it.increment(ec))
    {
      std::cout << *it << '\n';
    }

    return 0;
  }

On my system, it outputs:

  "x/b"

Using a `directory_iterator` instead does print both directories, as expected.

Reply via email to