This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Trouble with copy-ctor


Hi,

the following example looks like legal code to me:

struct A
{
    A(A&);
    A(int);
};

A a = 0;

But compiling it with "g++ -c" I get the following error:

bug.cpp: In function `void __static_initialization_and_destruction_0(int, int)':
bug.cpp:8: no matching function for call to `A::A(A)'
bug.cpp:5: candidates are: A::A(int)
bug.cpp:3:                 A::A(A&)
bug.cpp:8:   initializing temporary from result of `A::A(int)'

IMHO there should be a call to "A(int)" to convert "0" into something of
type "A". Then a copy-ctor should be called to initialize "a" with this
value. The question is: Why is "A::A(A&)" non-matching?

The temporary from the call "A::A(int)" isn't "const", is it?
Then one should be able to call the copy-ctor "A::A(A&)".
Am I wrong, or is this a bug in gcc?
I get error messages with gcc 2.95.2, 3.0.x, and 3.1 20011231.

If g++ is at fault, I can file a PR into GNATS.

Greetings,
Volker Reichelt



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]