This is a bit of an inverse of all the "lvalue required as left operand of assignment" error questions.
I have a class that overloads operator[], but only the version that returns a temporary. If it were to return an int:
struct Foo
{
int operator[]( int idx ) const { return int( 0 ); }
};
Foo f;
f[1] = 5;
I would rightfully get the lvalue compiler error. If it returns a struct type however, the compiler ( GCC 7.2 in this case ) doesn't complain at all:
struct Bar {};
struct Foo
{
Bar operator[]( int idx ) const { return Bar(); }
};
Foo f;
f[1] = Bar();
Why wouldnt this complain in the same way if Bar is a temporary and it doesnt have an specialized operator =? Alternate question, is there some way to make this complain? Clearly this is a coding error if it were to be used this way