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