[newbie] Boost 1.39 in Mac XCode get "error: attempt to copy-construct an iterator from a singular iterator."

Hi, I'm new to boost. It seems that the coding of boost library is not very clean as it makes the debug code aborted by generating a runtime error like this: "error: attempt to copy-construct an iterator from a singular iterator.". Here are the steps to reproduce the fault: I downloaded the source and install the things to /usr/local/include as well as /usr/local/lib. I test the code by creating a "C++ Tool" project in XCode. 1. Create a new C++ Tool project. 2. Add the header search path /usr/local/include/boost-1_39 and library search path /usr/local/lib into the project. 3. Add "Other Linker Flags" "-lboost_system-xgcc40-mt" in the project setting. 4. Edit the main.cpp as below: #include <iostream> #include<boost/asio.hpp> int main (int argc, char * const argv[]) { boost::asio::io_service io_service; boost::asio::ip::tcp::acceptor acceptor(io_service); std::cout<<"acceptor instantiated."<<std::endl; return 0; } 5. Build and run. Check out the result from the Console window as captured below: [Session started at 2009-07-28 16:00:10 +0800.] * /Developer/SDKs/MacOSX10.5.sdk/usr/include/c++/4.0.0/debug/safe_iterator.h:127: * * error: attempt to copy-construct an iterator from a singular iterator.* ** *Objects involved in the operation:* *iterator "this" @ 0x0x100480 {* *type = N11__gnu_debug14_Safe_iteratorIN10__gnu_norm14_List_iteratorISt4pairIiPN5boost4asio6detail16reactor_op_queueIiE7op_baseEEEEN15__gnu_debug_def4listISB_SaISB_EEEEE (mutable iterator);* * state = singular;* *}* *iterator "other" @ 0x0xbffff364 {* *type = N11__gnu_debug14_Safe_iteratorIN10__gnu_norm14_List_iteratorISt4pairIiPN5boost4asio6detail16reactor_op_queueIiE7op_baseEEEEN15__gnu_debug_def4listISB_SaISB_EEEEE (mutable iterator);* * state = singular;* *}* [Session started at 2009-07-28 16:00:10 +0800.] GNU gdb 6.3.50-20050815 (Apple version gdb-966) (Tue Mar 10 02:43:13 UTC 2009) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-apple-darwin".sharedlibrary apply-load-rules all Attaching to process 3497. The Debugger Debugger is attaching to process It generates a runtime error "error: attempt to copy-construct an iterator from a singular iterator.". However, if I compile the code in terminal: g++ -o test -g -Wall main.cpp -lboost_system-xgcc40-mt It runs okay without any runtime error. Regards, Victor Tsang

On 28 Jul 2009, at 09:10, Victor Tsang wrote:
Hi, ...
The Debugger Debugger is attaching to process
It generates a runtime error "error: attempt to copy-construct an iterator from a singular iterator.".
However, if I compile the code in terminal: g++ -o test -g -Wall main.cpp -lboost_system-xgcc40-mt
It runs okay without any runtime error.
To duplicate the error from the command line, add ' -D_GLIBCXX_DEBUG ' to the command line, which turns on g++'s iterator debugging. Doing this, I can duplicate your problem. The problem can be boiled down to the following, illegal, code. #include <vector> #include <list> int main(void) { std::vector<std::list<int>::iterator> v; v.resize(1); } The code can be fixed (although there may be other occurrences of similar problems) by changing around line 220 on asio/detail/ hash_map.hpp from: // Update number of buckets and initialise all buckets to empty. buckets_.resize(num_buckets); for (std::size_t i = 0; i < buckets_.size(); ++i) buckets_[i].first = buckets_[i].last = end; to: // Update number of buckets and initialise all buckets to empty. bucket_type bucket; bucket.first = bucket.last = end; buckets_.resize(num_buckets, bucket); I'm surprised boost isn't tested with iterator checking. Any particular reason, or has simply no-one tried?
participants (2)
-
Christopher Jefferson
-
Victor Tsang