This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: Why does this not compile?
- From: Matthijs van Duin <matthijs at cds dot nl>
- To: "Harron, Vince" <vharron at soe dot sony dot com>,'Florian Weimer' <fw at deneb dot enyo dot de>
- Cc: gcc at gcc dot gnu dot org, aoliva at redhat dot com
- Date: Mon, 20 May 2002 00:34:05 +0200
- Subject: RE: Why does this not compile?
- References: <9EAA79BA8878D511B5BD00D0B7B75313054BE801@mail-sd.station.sony.com>
At 15:26 -0700 19-05-2002, Harron, Vince wrote:
>Either way, I'm having trouble imagining why the spec forbids this in the
>first place. So what if I modify a temporary? Any ideas?
Well, because a temporary object is just a value, it's an expression.
Trying to change binary(b) is kinda like trying to change 3+4.
For example, take:
void foo(myclass& x);
int main() {
myclass x;
foo(x);
foo(myclass(x));
return 0;
}
the first foo works, the second doesn't. if it's not entirely clear
why not, replace "myclass" by "int" and look at it again :)
Just because in practice it *is* possible to change a temporary
myclass while it's not possible to change a temporary int, doesn't
mean it's also allowed.
- xmath
Matthijs van Duin
- PGP Key: 0x2D6F0BA7
- FP: 205D F7BA FFAD 9070 AB9E C5A8 BDB0 CA1B 2D6F 0BA7 -