Bug 19960 – ElementType!(char[]) + betterC = wrong type

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2019-06-14T00:56:37Z
Last change time
2024-12-13T19:03:55Z
Keywords
betterC
Assigned to
No Owner
Creator
SrMordred
Moved to GitHub: dmd#19583 →

Comments

Comment #0 by patric.dexheimer — 2019-06-14T00:56:37Z
//dmd main.d -betterC import std.range; pragma(msg, ElementType!(char[]) ); //main.d(2): Error: Cannot pass argument void to pragma msg because it is void //dmd main.d //dchar
Comment #1 by bugzilla — 2023-01-15T06:42:32Z
I'm getting an output of `void`. The implementation of this is in std.range.primitive, and is: template ElementType(R) { static if (is(typeof(R.init.front.init) T)) alias ElementType = T; else alias ElementType = void; } What is happening is R.init.front.init is failing to compile, hence the `void` result. It is falling victim to the autodecoder, which can be seen by compiling it as regular D code, and the output is `dchar`, not `char`. The `dchar` comes about from the autodecoding, and we're stuck with that at the moment. Autodecoding is never going to work with betterC, because it uses the GC and throws exceptions. So I don't know how to fix this. If we change the `char` to `ubyte`, it works and prints `ubyte`. If we ever do remove autodecoding, this bug report should resolve itself.
Comment #2 by alphaglosined — 2023-01-15T06:52:50Z
> Autodecoding is never going to work with betterC, because it uses the GC and throws exceptions. So I don't know how to fix this. Assert; this affects far too much at compile time to not have it work even if it would if given the wrong input crash a program. One option might be value-type exceptions if I ever get around to finishing the DIP. But I'm not keen on the idea of changing the exception mechanism depending on compiler flags for code like this, so it would be an all-or-nothing change.
Comment #3 by robert.schadek — 2024-12-13T19:03:55Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19583 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB