An undefined value is returned when a derived type D is returned by a
function with a return type that is a base type of D when the flag
-freg-struct-return is turned on.
Here is an example of a program that runs incorrectly using the
flag -freg-struct-return but correctly without it:
#include <iostream.h>
class Base
{
int value;
public:
Base() : value(1) { }
operator int() const { return value; }
};
class Derived : public Base
{
};
class Other
{
Derived derived;
public:
operator Base() const { return derived; }
};
main()
{
cout << Base(Other()) << endl;
}