[Bug c++/13703] New: Conditional assignment missing constructor

todd dot meade at businessobjects dot com gcc-bugzilla@gcc.gnu.org
Thu Jan 15 21:37:00 GMT 2004


GCC versions 2.96 through 3.2.X exhbit the same error (missing constructor, 
yet address is destructed) when assigning a class in a conditional assignment:

SomeClass x = bool ? y.x : SomeClass();

GCC 2.95 and GCC 3.3 are fine.

Doesn't appear to be platform specifc (only tried Linux, Win32/cygwin, 
Solaris).

See the very simple test case to reproduce
---
#include <iostream>

using namespace std;

class MyTest
{

public:
    MyTest()
    {
        cout << "MyTest() called: " << this << endl;
    }

    MyTest(const MyTest& t)
    {
        cout << "MyTest(const MyTest&) called: " << this << " --> ";
        *this = t;
    }

    void operator = (const MyTest& t)
    {
        cout << "operator = (const MyTest&) called: " << this << " <-- " << &t 
<< endl;
    }

    ~MyTest()
    {
        cout << "~MyTest() called: " << this << endl;
    }
};

class MyBigTest
{

public:
    MyBigTest()
    {
        cout << "MyBigTest called --> ";
    }

    ~MyBigTest()
    {
        cout << "~MyBigTest called --> ";
    }

    MyTest t;
};

MyBigTest getTest()
{
    return MyBigTest();
}

int main(int argc, char *argv[])
{
    {
        MyTest t;

        bool bTooManyDestructors = true;

        if (argc > 1)
        {
            if (argc > 2)
                bTooManyDestructors = false;

            t = (bTooManyDestructors ? getTest().t : MyTest());

        }
        else
        {
            t = getTest().t;

        }
    }

    cout << "exiting..." << endl;

    return 0;
}

-- 
           Summary: Conditional assignment missing constructor
           Product: gcc
           Version: 3.2.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: todd dot meade at businessobjects dot com
                CC: gcc-bugs at gcc dot gnu dot org


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



More information about the Gcc-bugs mailing list