Bug 15945 – sizeof on an invalid type seems to compile.

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-04-21T14:15:25Z
Last change time
2018-01-05T13:28:55Z
Assigned to
No Owner
Creator
John Colvin

Comments

Comment #0 by john.loughran.colvin — 2016-04-21T14:15:25Z
size_t foo(T)() { return T[0].sizeof; } void main() { auto a = foo!(ubyte[])(); assert(a == 1); } Seems like either that shouldn't compile, or (maybe?) the assert should pass. Currently, it compiles and the assert fails.
Comment #1 by Marco.Leise — 2016-04-25T02:40:58Z
You are not indexing T, you are creating a static array of length 0, hence why it returns 0 for the size. Try T.init[0] instead to use an instance of T.
Comment #2 by john.loughran.colvin — 2016-04-25T08:56:21Z
(In reply to Marco Leise from comment #1) > You are not indexing T, you are creating a static array of length 0, hence > why it returns 0 for the size. Try T.init[0] instead to use an instance of T. Yeah that's what I did in the actual code, no idea why I didn't spot that it was a static array.
Comment #3 by github-bugzilla — 2017-05-26T13:30:57Z
Comment #4 by john.loughran.colvin — 2017-05-26T13:36:38Z
Note for archaeologists: commit above has nothing to do with this.
Comment #5 by github-bugzilla — 2017-06-17T11:34:53Z
Comment #6 by github-bugzilla — 2018-01-05T13:28:55Z