http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50184

             Bug #: 50184
           Summary: Segmentation fault. Copy Constructor.
    Classification: Unclassified
           Product: gcc
           Version: 4.4.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: eugen...@yandex.ru


#include <iostream>
#include <map>
using namespace std;

class CData
{
    class CItem
    {
    public:
        string m_str1;
    };

public:
    map<string, CItem>  m_map;

    int                 m_nWaitTime2ReadSS;
    int                 m_eQueueOrderType;

    //- Data ---------------
    bool                m_bDFRead;
    std::string         m_strDFName;
    int                 m_nDFLoopCount;
    int                 m_nDFLoopTimeout;
    int                 m_nDFMsgTimeout;
};

class A
{
public:
    CData func()
    {
        CData data;
        data.m_map["Test"].m_str1 = "Data";
        return data;
    }
};

class B : public CData
{
public:
    template <class T>
    B(T& a)
        : CData(a.func())
    {
        map<string, CItem>::iterator it = m_map.begin();
        for (; it != m_map.end(); it++)//In this place m_map.end() returns
wrong value as result I get segmentation fault.
//I noticed that copy constructor when I added one into CData is never called.
        {
            cout << (*it).first<< " "<<(*it).second.m_str1<<"\n";
        }
        cout << "GOOD"<<"\n";
    }
};

int main()
{
    A a;
    B b1(a);
    return 0;
}

Result of this code is Segmentation fault.

Reply via email to