[Issue 1472] New: Be more clever about detecting assigment to non-l-values

BCS ao at pathlink.com
Tue Sep 4 12:01:05 PDT 2007


Reply to d-bugmail at puremagic.com,

> http://d.puremagic.com/issues/show_bug.cgi?id=1472
> 
> Summary: Be more clever about detecting assigment to
> non-l-values
> Product: D
> Version: 1.020
> Platform: PC
> OS/Version: Windows
> Status: NEW
> Severity: enhancement
> Priority: P2
> Component: DMD
> AssignedTo: bugzilla at digitalmars.com
> ReportedBy: wbaxter at gmail.com
> It should be an error if you return a struct and then immediately just
> set one of its fields in some way.
> 
> For instance
> struct Struct {
> int i;
> set_i(int _i) { i=_i; }
> }
> class Foo {
> Struct get_struct() { return s; }
> Struct s;
> }
> Struct s;
> Foo x = new Foo;
> x.get_struct() = s;  // currently an error -- good
> x.get_struct.i = 10;  // currently not an error -- bad
> x.get_struct.set_i(10); // also current not an error -- bad

this is NOT an error if set_i(int) has side effects. Requiring the compiler 
to test for side effects here would be, IMO, bad.




More information about the Digitalmars-d-bugs mailing list