copy ctor required ?

J

jg

For the following case:
#include <stdio.h>

class A {
public:
A() { printf("%p A()\n", this); }
~A() { printf("%p ~A()\n", this); }
A (A& a) { printf("%p A(A&)\n", this); }
};


int main ()
{
({A a; a;});
}

Does C++ stardard require A's copy constructor be invoked (for a
temporary) ?
If so, which part of Standard requires it ?

By the way, g++ gives the following:
0xbfda64e0 A()
0xbfda64f0 A(A&)
0xbfda64e0 ~A()
0xbfda64f0 ~A()

JG
 
A

Andrey Tarasevich

jg said:
For the following case:
#include <stdio.h>

class A {
public:
A() { printf("%p A()\n", this); }
~A() { printf("%p ~A()\n", this); }
A (A& a) { printf("%p A(A&)\n", this); }
};


int main ()
{
({A a; a;});
}

Does C++ stardard require A's copy constructor be invoked (for a
temporary) ?

The above code is not a valid C++ program, so the standard can't
possibly say anything about it. The feature you are trying to use is a
GCC-specific language extension. Consult GCC documentation or ask in
GCC-specific newsgroup.
 
J

jg

The above code is not a valid C++ program, so the standard can't
possibly say anything about it. The feature you are trying to use is a
GCC-specific language extension. Consult GCC documentation or ask in
GCC-specific newsgroup.

Right, a statement expr is a gcc/g++ extension. The gcc/g++ docs have
"the result value of a statement expression undergoes array and
function pointer decay,
and is returned by value to the enclosing expression"

So, by "returned by value", a temporary is required under the gcc/g++
extension.

Thanks
JG
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top