Bug 10123 – Can't subtract positive number from length of array of struct with disabled default construction

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-05-20T04:38:29Z
Last change time
2022-11-29T13:30:13Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Denis Shelomovskii
Depends on
10124

Comments

Comment #0 by verylonglogin.reg — 2013-05-20T04:38:29Z
--- struct S { @disable this(); } void main() { S[] arr = [S.init, S.init, S.init]; --arr.length; // Error: struct main.S default construction is disabled arr.length -= 1; // Same error size_t n = 1; arr.length -= n; // Same error } ---
Comment #1 by verylonglogin.reg — 2013-05-20T04:53:15Z
Looks like Issue 10124 have to be fixed first.
Comment #2 by b2.temp — 2019-03-30T12:12:56Z
I don't think this is a valid issue. When an array is shrink, its memory might be copied to another location. a struct with self reference would then become unsafe. You cannot speculate on the implementation details of the GC allocator.