[Issue 6578] New: Ignored const with struct with constructor
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Aug 30 04:57:51 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6578
Summary: Ignored const with struct with constructor
Product: D
Version: D2
Platform: x86
OS/Version: Windows
Status: NEW
Keywords: accepts-invalid, diagnostic
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2011-08-30 04:57:48 PDT ---
In DMD 2.055head this compiles and runs with no errors:
struct Foo {
int x;
this(int x_) { this.x = x_; }
}
void main() {
auto f1 = new const(Foo)(1);
f1.x++;
auto f2 = new immutable(Foo)(1);
f2.x++;
auto f3 = const(Foo)(1);
f3.x++;
auto f4 = immutable(Foo)(1);
f4.x++;
}
While this generates two errors:
struct Foo {
int x;
}
void main() {
auto f5 = const(Foo)(1);
f5.x++; // error
auto f6 = immutable(Foo)(1);
f6.x++; // error
}
I think in the first program the f1,f2,f3,f4 structs too need to raise a
compile-time error.
Thanks to Timon Gehr for a suggestion.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list