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
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