references and l-values

H

homsan toft

Hi,

Trying to read the standard...
Function returns are rvalues, except references [3.10.5].
Object constructors or functions returning classes, are also rvalues (fn 47 to 3.10.2)
I take it it's the same for members of structs returned from function calls?
[3.10.10]: "An lvalue for an object is necessary in order to modify the object except
that an rvalue of class type can also be used to modify its referent under certain
circumstances" (eg member function calls)

But what about reference members of structs returned from function calls?
Comeau online and g++ allow the following, MSVC (7.1) doesn't.

======================================

struct ref {
int& second;
ref(int& i) : second(i) {}
};

ref getref() {
static int a;
return ref(a);
}


int main()
{
int a;
ref(a).second = 3; // MSVC C2106: not l-value
getref().second = 9; // MSVC C2106: not l-value

return 0;
}

======================================

....a bug in MSVC?

Thanks,

homsan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top