Checked!({short, ushort, byte, char}, Throw): compilation fails
kdevel
kdevel at vogtner.de
Fri Apr 17 01:31:22 UTC 2020
Sorry for this lengthy post:
```x.d
void foo (T) ()
{
import std.experimental.checkedint;
alias CT = Checked!(T, Throw);
CT a = CT.min;
CT x;
--x;
CT b = x;
CT c = a / b;
}
void bar (T) ()
{
import std.stdio;
try foo!T ();
catch (Exception e)
writefln ("caught <%s>", e.msg);
}
void main ()
{
bar!byte;
bar!char;
bar!ushort;
bar!short;
bar!uint;
bar!int;
bar!ulong;
bar!long;
}
```
$ dmd x.d
[...]/linux/bin64/../../src/phobos/std/experimental/checkedint.d(1410): Deprecation: integral promotion not done for `~cast(byte)0`, use '-preview=intpromote' switch or `~cast(int)(cast(byte)0)`
x.d(9): Error: template
`std.experimental.checkedint.Checked!(byte,
Throw).Checked.__ctor` cannot deduce function from argument types
`!()(Checked!(int, Throw))`, candidates are:
[...]/linux/bin64/../../src/phobos/std/experimental/checkedint.d(331): `__ctor(U)(U rhs)`
x.d(15): Error: template instance `x.foo!byte` error instantiating
x.d(22): instantiated from here: `bar!byte`
x.d(4): Error: template instance
`std.experimental.checkedint.Checked!(char, Throw)` does not
match template declaration `Checked(T, Hook = Abort)`
with `T = char,
Hook = Throw`
must satisfy one of the following constraints:
` isIntegral!T
is(T == Checked!(U, H), U, H)`
x.d(15): Error: template instance `x.foo!char` error instantiating
x.d(23): instantiated from here: `bar!char`
[...]/linux/bin64/../../src/phobos/std/experimental/checkedint.d(1410): Deprecation: integral promotion not done for `~cast(ushort)0u`, use '-preview=intpromote' switch or `~cast(int)(cast(ushort)0u)`
x.d(9): Error: template
`std.experimental.checkedint.Checked!(ushort,
Throw).Checked.__ctor` cannot deduce function from argument types
`!()(Checked!(int, Throw))`, candidates are:
[...]/linux/bin64/../../src/phobos/std/experimental/checkedint.d(331): `__ctor(U)(U rhs)`
x.d(15): Error: template instance `x.foo!ushort` error
instantiating
x.d(24): instantiated from here: `bar!ushort`
[...]/linux/bin64/../../src/phobos/std/experimental/checkedint.d(1410): Deprecation: integral promotion not done for `~cast(short)0`, use '-preview=intpromote' switch or `~cast(int)(cast(short)0)`
x.d(9): Error: template
`std.experimental.checkedint.Checked!(short,
Throw).Checked.__ctor` cannot deduce function from argument types
`!()(Checked!(int, Throw))`, candidates are:
[...]/linux/bin64/../../src/phobos/std/experimental/checkedint.d(331): `__ctor(U)(U rhs)`
x.d(15): Error: template instance `x.foo!short` error
instantiating
x.d(25): instantiated from here: `bar!short`
$ dmd --version
DMD64 D Compiler v2.090.1
Copyright (C) 1999-2019 by The D Language Foundation, All Rights
Reserved written by Walter Bright
Is Checked expected to work with the types byte, char, ushort and
short? If so shall I file a bug report?
More information about the Digitalmars-d-learn
mailing list