[Issue 1472] New: Be more clever about detecting assigment to non-l-values
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Sep 4 11:52:02 PDT 2007
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
These errors are especially helpful in finding bugs when porting C++ code that
returned mutable references initially. If you convert those to be
value-returning functions then you need to find all the places in the code that
are assuming the return value is an l-value.
--
More information about the Digitalmars-d-bugs
mailing list