Bug 15412 – Operator ^^= fails to compile for many numeric type combinations

Status
NEW
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2015-12-06T04:08:02Z
Last change time
2024-12-13T18:46:01Z
Assigned to
No Owner
Creator
thomas.bockman
Moved to GitHub: dmd#19075 →

Comments

Comment #0 by thomas.bockman — 2015-12-06T04:08:02Z
This code: N n; M m; n ^^ = m; Seems to be lowered to this: N n; M m; n = pow(n, m); For many numeric type combinations, this will fail to compile, yielding "Error: cannot implicitly convert expression (pow(cast(N)n, cast(M)m)) of type R to N", where R is some other numeric type. In particular, operator ^^= is completely unusable with byte, ubyte, short, and ushort, since for those types pow returns int, which cannot be implicitly converted to a lesser type. The fix is to include an explicit cast in the lowering: N n; M m; n = cast(N) pow(n, m); This would make the behaviour of ^^= consistent with the other assignment operators (like *=) which do not have this problem. // Full test code /////////////////////////////////// import std.traits : NumericTypeList; import std.stdio; void main(string[] args) { foreach(N; NumericTypeList) { foreach(M; NumericTypeList) { N n = 1; M m = 1; if(!__traits(compiles, n += m)) writeln(N.stringof ~ " ^^= " ~ M.stringof ~ " fails to compile."); } } }
Comment #1 by robert.schadek — 2024-12-13T18:46:01Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19075 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB