Bug 15261 – [dmd-internal] Trivial problem in BinExp.checkOpAssignTypes
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-10-30T01:13:00Z
Last change time
2016-01-03T14:02:15Z
Keywords
pull
Assigned to
nobody
Creator
k.hara.pg
Comments
Comment #0 by k.hara.pg — 2015-10-30T01:13:55Z
In BinExp.checkOpAssignTypes:
if (op == TOKmulass ||
op == TOKdivass ||
op == TOKmodass ||
TOKaddass || // TOK enum is used as a boolean value!
op == TOKminass ||
op == TOKpowass)
{
if ((type.isintegral() && t2.isfloating()))
{
warning("%s %s %s is performing truncating conversion", type.toChars(), Token.toChars(op), t2.toChars());
}
}
But this is not a real problem, because:
1. checkOpAssignTypes is called only from BinAssignExp.semantic
2. BinAssignExp.semantic is used by these concrete classes derived from BinAssignExp:
(Add|Min|Mul|Div|Mod|Pow)AssignExp
(And|Or|Xor)AssignExp
(Shl|Shr|Ushr)AssignExp
3. However, BinAssignExp.e2.type can have floating point type only in:
(Add|Min|Mul|Div|Mod|Pow)AssignExp
Other cases are rejected before the call of checkOpAssignTypes in BinAssignExp.semantic.
Test case (compile with -o- -w):
void main()
{
int x;
double y;
x += y; // AddAssignExp -> warning, expected
x -= y; // MinAssignExp -> warning, expected
x *= y; // MulAssignExp -> warning, expected
x /= y; // DivAssignExp -> warning, expected
x %= y; // ModAssignExp -> warning, expected
x ^^= y; // PowAssignExp -> warning, expected
x &= y; // AndAssignExp -> error, does not reach to checkOpAssignTypes call
x |= y; // OrAssignExp -> error, ditto
x ^= y; // XorAssignExp -> error, ditto
x <<= y; // ShlAssignExp -> error, ditto
x >>= y; // ShrAssignExp -> error, ditto
x >>>= y; // UshrAssignExp -> error, ditto
}