Bug 15384 – assignment is sometimes still accepted as a condition
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-11-27T08:24:32Z
Last change time
2018-01-03T22:32:03Z
Keywords
pull
Assigned to
No Owner
Creator
BugsBunny
Comments
Comment #0 by eponymousalias — 2015-11-27T08:24:32Z
Problem seen with: DMD64 D Compiler v2.067.1
bool cond = true;
do {
// stuff
} while (cond = false);
yields:
Error: assignment cannot be used as a condition, perhaps == was meant?
But:
bool cond = true;
do {
// stuff
} while (cond = false, cond = false);
passes the compiler without complaint, even though it also uses an
assignment as a condition.
Comment #1 by lt.infiltrator — 2015-12-01T02:37:29Z
I assume that this has to do with the way in which the comma operator works. The compiler then sees it not as two assignments, but the output of the comma operator (which is just a value). Not sure how difficult it would be to get the compiler to track down into a comma operator, since you can do arbitrary work inside it.