[Issue 23268] clamp no longer accepts shorts

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jul 25 11:48:49 UTC 2022


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

--- Comment #3 from RazvanN <razvan.nitu1305 at gmail.com> ---
(In reply to RazvanN from comment #2)
> Additional information: a reduction of the phobos code that manifests in
> this case is:
> 
> void main()
> {
>      clamp(short.init, short.init, cast(const)short.init);                  
> 
> }
>   
> T1 clamp(T1, T2, T3)(T1 val, T2 lower, T3 upper)
> if (is(typeof(val < lower ? lower : val > upper ? upper : val) : T1))
> {
>       return val < lower ? lower : val > upper ? upper : val;
> }
> 
> The problem is that the resulting type of the ternary expression is int
> instead of shared. It wrongfully casts the operands to int, as a result of

I meant: "is int instead of short"

> 16235.

--


More information about the Digitalmars-d-bugs mailing list