g++4.3.0 is wrongly eliding the copy constructor and the assignment of a
struct. Look at the following code:

#include <iostream>
#include <complex>

struct Complex {
        std::complex<double> value;
        };

const Complex one = { 1 };

int main() {
        Complex z = one, w;
        w = one;
        std::cout << "one = " << one.value << std::endl;
        std::cout << "z = " << z.value << std::endl;
        std::cout << "w = " << w.value << std::endl;
}

It prints:
one = (1,0)
z = (0,0)
w = (0,0)

When the value is of type double instead of complex<double> the problem doesn't
occur. Also, this doesn't happen using the compiler switch
-fno-elide-constructors .


-- 
           Summary: Default copy constructor and assignment operator ignored
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mjdcc at cftp dot ist dot utl dot pt


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

Reply via email to