[Boost-bugs] [Boost C++ Libraries] #6778: directory_iterator and recursive_directory_iterator has inconsistent behavior with STL iterator when assignment operator=() is involved.

Subject: [Boost-bugs] [Boost C++ Libraries] #6778: directory_iterator and recursive_directory_iterator has inconsistent behavior with STL iterator when assignment operator=() is involved.
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-04-09 23:49:26


#6778: directory_iterator and recursive_directory_iterator has inconsistent
behavior with STL iterator when assignment operator=() is involved.
--------------------------------------------------------------------------------------+
 Reporter: Chih-Yao Hsieh <josephsieh@…> | Owner: bemandawes
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: filesystem
  Version: Boost 1.49.0 | Severity: Problem
 Keywords: directory_iterator, recursive_directory_iterator, assignment operator=() |
--------------------------------------------------------------------------------------+
 For example, in std::vector, the following code shows that *vIterator_1
 prints out intVec[1] and *vIteraotr_2 prints out intVec[0]. (The
 assignment operator=() does not make those two iterators link together...)
 {{{
 std::vector<int> intVec(10);
 intVec[1] = 1;
 std::vector<int>::iterator vIterator_1 = intVec.begin();

 // iterator assignment operator=() now get involved.
 std::vector<int>::iterator vIterator_2 = vIterator_1;
 ++vIterator_1; // vIterator_2 does not increment.
 std::cout << "*vIterator_1: " << *vIterator_1;
 std::cout << "*vIterator_2: " << *vIterator_2;
 }}}

 On the other hand, the following example shows that dirIterator1->path()
 and dirIterator2->path() both contains '/home/user/test/2.txt' which is
 not consistent with STL iterator behavior. Since iterators behaves like
 pointers, after calling vIterator_2 = vIterator_1;, vIterator_2 and
 vIterator_1 should stays independent. The problem seems to be
 directory_iterator forgot to implement the copy constructor and assignment
 operator=().

 {{{
 // assuming that under /home/user/test, there are 1.txt and 2.txt
 boost::filesystem::path rootPath("/home/user/test");
 boost::filesystem::directory_iterator dirIterator1(rootPath);

 // Now assignment operator=() got involved.
 boost::filesystem::directory_iterator dirIterator2 = dirIterator1;

 // This line causes dirIterator1 and dirIterator2 both got incremented ...
 ++dirIterator1;

 std::cout << "dirItertor1: " << dirIterator1->path().string() <<
 std::endl;
 std::cout << "dirItertor2: " << dirIterator2->path().string() <<
 std::endl;
 }}}


 == Note ==
 The symptom occurred in:

 boost::filesystem::directory_iterator[[BR]]
 boost::filesystem2::directory_iterator[[BR]]
 boost::filesystem3::directory_iterator[[BR]]
 boost::filesystem::recursive_directory_iterator[[BR]]
 boost::filesystem2::recursive_directory_iterator[[BR]]
 boost::filesystem3::recursive_directory_iterator[[BR]]

 under all platforms.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/6778>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:09 UTC