weird things with safe iterators in xcode debug configurations
weird things with safe iterators in xcode debug configurations
- Subject: weird things with safe iterators in xcode debug configurations
- From: "Mattias Holm" <email@hidden>
- Date: Thu, 11 Dec 2008 10:50:42 +0100
I have a project that consist of a library and an application, the lib and app is written in C++, and when I run it in debug mode, I get messages like:
/usr/include/c++/4.0.0/debug/safe_iterator.h:114:error: attempt to
initialize an iterator that will immediately become singular.
Objects involved in the operation:
iterator "this" @ 0x0xbffff950 {
type = N11__gnu_debug14_Safe_iteratorIN10__gnu_norm14_List_iteratorIPSsEEN15__gnu_debug_def4listIS3_SaIS3_EEEEE (mutable iterator);
state = singular;
references sequence with type `N15__gnu_debug_def4listIPSsSaIS1_EEE' @ 0x0xbffff950
}
Abort trap
With release mode this does not happen. It also does not happen if I do not build this as a library, and neither if all the std::lists in an object have got at least one push_back (i.e. they are not empty).
I have reduced my failing code to the code listed below.
The following manual build commands will result in the issue (these where extracted from the xcodebuild output):
gcc -x c++ -O0 -c foo.cc -o foo.o
libtool -static foo.o -o libfoobar.a
gcc -x c++ -O0 -D_GLIBCXX_DEBUG=1 -D_GLIBCXX_DEBUG_PEDANTIC=1 -c test.cc
g++ -arch i386 test.o -L. -lfoobar -o test
(then run ./test)
Note that if you uncomment the line saying: list1.push_back(b), then the application will run and not crach with the singular error message.
Any idea of why this happens, is it a bug in the safe iterators in the glibc debug code or is the problem actually in my app? Is there a workaround I can do to disable the GLIBC debug flags for the debug configuration? I looked in the compiler setup for my target, but I could not find the relevant option.
The files in question are the following:
######### test.cc
#include <string>
#include <list>
#include <iostream>
#include "foo.hh"
int main(int argc, char * const argv[]) {
A *foo = new A();
for (std::list<std::string*>::const_iterator it = foo->list0.begin();
it != foo->list0.end() ; it ++)
{
std::cout << *(*it) << "\n";
}
return 0;
}
######### Foo.cc
#include <string>
#include <list>
#include "foo.hh"
A::A() {
std::string *a = new std::string("foo");
std::string *b = new std::string("bar");
list0.push_back(a);
//list1.push_back(b);
}
######### Foo.hh
#include <string>
#include <list>
class A {
public:
std::list<std::string*> list0;
std::list<std::string*> list1;
A();
};
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden