Bug 16207 – CTFE cast from void* to ubyte* doesn't work

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-06-26T22:13:43Z
Last change time
2024-12-13T18:48:40Z
Keywords
CTFE
Assigned to
No Owner
Creator
Walter Bright
See also
https://issues.dlang.org/show_bug.cgi?id=8901
Moved to GitHub: dmd#19149 →

Comments

Comment #0 by bugzilla — 2016-06-26T22:13:43Z
int hashOf( const(void)[] buf ) { auto data = cast(const(ubyte)*) buf.ptr; return 3; } enum hashval = hashOf("Sample_string"); ------------------------- bug.d(4): Error: pointer cast from const(void)* to const(ubyte)* is not supported at compile time bug.d(8): called from here: hashOf("Sample_string")
Comment #1 by uplink.coder — 2016-06-26T23:11:23Z
The only way around this is passing ubyte[] instead of void[] I actually like the rigorous type-safety at CTFE. It's not a bug, It's a feature!
Comment #2 by ag.dlang — 2016-07-10T20:15:25Z
I know what a "void *" is for, but what is the intent of a "const(void)[]"? Does it have a valid length? Does it behave any differently than a "void[]"?
Comment #3 by ag0aep6g — 2016-07-10T20:27:44Z
(In reply to Andrew Godfrey from comment #2) > I know what a "void *" is for, but what is the intent of a "const(void)[]"? > Does it have a valid length? Does it behave any differently than a "void[]"? Please ask such questions in the Learn group of the forum: http://forum.dlang.org/group/learn Regarding void[], see http://dlang.org/spec/arrays.html (section "Void Arrays" near the bottom). If that doesn't answer all your questions, please make a thread in the forum.
Comment #4 by ag.dlang — 2016-07-10T21:04:55Z
(In reply to ag0aep6g from comment #3) > (In reply to Andrew Godfrey from comment #2) > > I know what a "void *" is for, but what is the intent of a "const(void)[]"? > > Does it have a valid length? Does it behave any differently than a "void[]"? > > Please ask such questions in the Learn group of the forum: > http://forum.dlang.org/group/learn > > Regarding void[], see http://dlang.org/spec/arrays.html (section "Void > Arrays" near the bottom). If that doesn't answer all your questions, please > make a thread in the forum. Thanks for the link. I've read that before but didn't retain it. To this bug, I'm still wondering if it's specific to the const case.
Comment #5 by robert.schadek — 2024-12-13T18:48:40Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19149 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB