D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21608 - [betterC] static slices are allowed and have the wrong size
Summary: [betterC] static slices are allowed and have the wrong size
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All Linux
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-02-03 21:04 UTC by LucienPe
Modified: 2021-02-04 00:15 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description LucienPe 2021-02-03 21:04:31 UTC
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 kinke 2021-02-03 22:39:41 UTC
A slice is a fat pointer, nothing more. So no direct dependency on TypeInfos and no reason to disallow them for -betterC.
Comment 2 moonlightsentinel 2021-02-04 00:15:22 UTC
Also, sizeof returns the size of the pointer + length, not the actual array.