Am Donnerstag, 9. November 2006 13:43 schrieb Ozgur Ugras BARAN:
> On 11/9/06, Georg Baum <[EMAIL PROTECTED]> wrote:
> > Ozgur Ugras BARAN wrote:
> >
> > > This patch solves the crash while calling Qt4-TOC dialog in 
Linux /gcc-4.1
> >
> > Are you sure?
> 
> I have tested here and it works now..
> >
> > The old code is perfectly valid for a std::map: if the element does not
> > exist it is created. I don't understand at all how using insert() 
instead
> > of operator[] could solve a crash.
> >
> What I understand is map::operator[] returns mapped_type&,  (for this
> case a const_iterator&).

Yes.

> When you use operator = you try to 
> copy-construct with another const_iterator. This is erroneous, since
> you cannot dereference the first.

No, that is OK: I can assign a const_iterator to another const_iterator. 
Otherwise the statement some lines above

TocIterator iter = toc.begin();

would not work.

> Pair, however, packs two items first.
> 
> I guess this make sense, or just test it and see the result. )
> 
> Anyway, I am not that sure. This may be a gcc bug also.

Yes, I think so: operator[] first default constructs a TocIterator if the 
key is absent:

__i = insert(__i, value_type(__k, mapped_type()));

That default constructed iterator mapped_type() is singular, since it does 
not point enywhere. Then in the value_type() constructor (value_type == 
std::pair) the copy constructor is called -> the singularity check fails.

The strange thing is that I could not reproduce the problem with this 
little test program:


#define _GLIBCXX_CONCEPT_CHECKS 1
#define _GLIBCXX_DEBUG 1
#define _GLIBCXX_DEBUG_PEDANTIC 1

#include <map>
#include <string>


int main()
{
        std::string s("hello");
        std::string::const_iterator i = s.begin();
        std::map<int, std::string::const_iterator> m;
        m[500] = i;
        return 0;
}



Georg

Reply via email to