By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 811 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

references and l-values

P: n/a
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
Dec 24 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.