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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jan 15 06:42:32 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=19960

--- Comment #1 from Walter Bright <bugzilla at digitalmars.com> ---
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.

--


More information about the Digitalmars-d-bugs mailing list