Bug 21608 – [betterC] static slices are allowed and have the wrong size

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
Linux
Creation time
2021-02-03T21:04:31Z
Last change time
2021-02-04T00:15:22Z
Assigned to
No Owner
Creator
LucienPe

Comments

Comment #0 by lucien.perregaux — 2021-02-03T21:04:31Z
Pretty much the title. Slices uses TypeInfo, which should be disallowed in betterC mode. --- import core.stdc.stdio; extern(C) void main() { static int[] a = [ 1, 2, 3, 4, 5, 6 ]; // Shouldn't be allowed printf("%lli", a.sizeof); // prints 16 instead of 24 } ---
Comment #1 by kinke — 2021-02-03T22:39:41Z
A slice is a fat pointer, nothing more. So no direct dependency on TypeInfos and no reason to disallow them for -betterC.
Comment #2 by moonlightsentinel — 2021-02-04T00:15:22Z
Also, sizeof returns the size of the pointer + length, not the actual array.