This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Temporaries
- To: gcc at gcc dot gnu dot org
- Subject: Temporaries
- From: linguist-gcc at rich-paul dot net
- Date: Sat, 27 May 2000 20:34:26 -0400 (EDT)
- Newsgroups: comp.std.c++
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