This page says a strange thing :-
The temporaries are created only if your program does not copy the return value to an object and example given is
UDT Func1(); // Declare a function that returns a user-defined type.
...
Func1(); // Call Func1, but discard return value.
// A temporary object is created to store the return
// value
but if i have done :-
UDT obj=Fuct1;
It appears to me that it will also create a temporary as follow:-
Func()
constructs a local object. Next, this local object is copy-constructed on the caller's stack, making a temporary object
that is used as the argument of obj's copy-constructor.
Am I wrong?
Is this has something to do with copy elision?
The page you cite it a description of the behavior of a specific compiler. Formally: the return value is always a temporary. In contexts where that temporary is used as the argument of a copy constructor (the object is copied), the standard gives explicit authorization for the compiler to elide the copy, “merging” the temporary with the named variable it is initializing. All the sentence you quote is saying is that this specific compiler always does his optimization (as do most other compilers).