This is the mail archive of the mailing list for the libstdc++ project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3 patch] Fix Filesystem TS directory iterators

directory_iterator and recursive_directory_iterator fail to meet this
requirement in

 The directory_iterator default constructor shall create an iterator
 equal to the end iterator value, and this shall be the only valid
 iterator for the end condition.

The current code creates the end iterator when an error occurs during
construction and an error_code parameter was used (so an exception
is not thrown, but construction finishes normally and sets the

This fixes it by creating a distinct error state that is not the end
iterator state:

 // An error occurred, we need a non-empty shared_ptr so that *this will
 // not compare equal to the end iterator.

This way the shared_ptr owns a null pointer, so (bool)_M_dir is false
(and we don't allow incrementing or dereferencing) but it can be
distinguished from an empty shared_ptr by comparing them using

(The order of the owner_before checks is chosen so that the common
case of testing iter != directory_iterator() should short-circuit and
only check the first condition).

There were a few other problems with directory iterators, including
the fact that the get_file_type function never worked because autoconf
the macro I was checking, _GLIBCXX_HAVE_STRUCT_DIRENT_D_TYPE.

I've removed the ErrorCode utility that was meant to simplify
clearing/setting an error_code that may or may not be present, but
really just obsfuscated things.

I'm also now consistently checking the skip_permission_denied flag
everywhere it matters.

Tested x86_64-linux, powerpc64le-linux, x86_64-dragonfly4.1, committed
to trunk.

Attachment: patch-fs-2.txt
Description: Text document

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]