Bug 41381 - Default copy constructor and assignment operator ignored
Summary: Default copy constructor and assignment operator ignored
Status: RESOLVED WORKSFORME
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-16 18:01 UTC by Marco
Modified: 2009-09-16 18:20 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.3.4 4.4.1 4.5.0
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marco 2009-09-16 18:01:42 UTC
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 .
Comment 1 Paolo Carlini 2009-09-16 18:20:48 UTC
Works for me with current compilers built out any active release branch.