This is the mail archive of the gcc@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]

Temporaries



Hello again, all.

I'm attempting to port some code that has the following definitions:
--------------------- cut here ---------------
class Set {
	public:
	Set &operator |= ( Set & );
	Set &operator | ( Set & );
};
Set &Set::operator | ( Set &rhs ) {
	return Set(rhs)|=lhs;
};
--------------------- cut here ---------------


Under visual c++, this is fine, but under gcc it is an error (not a warning),
because the non-const reference parameter of operator |= is being initialized
with an rvalue of type 'String'.

I always thought that an explicit constructor invocation yielded an lvalue.
Of course, that would permit nonsense like:

int()++;

which does nothing at all, but in some cases, like the one above, it would be
quite useful, saving from the longer:
{
	Set temp(lhs);
	temp |= rhs;
	return lhs;
};

What, if anything, does the standard say on this subject?  I couldn't find
anything in Stroustrup (3rd) to clarify.

Regards,
Rich





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