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.
Comment #2 by k.hara.pg — 2015-12-02T08:05:33Z
Comment #3 by github-bugzilla — 2016-01-06T12:45:32Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/95453495fdb38b9c596a977595ce23966fa55be7 fix Issue 15384 - assignment is sometimes still accepted as a condition 1. Add CommaExp.toBoolean to show error message. 2. Add checkAssignmentAsCondition and call it before semantic analysis to provide informative diagnostic. https://github.com/D-Programming-Language/dmd/commit/66ca6fe6cfe45f251664abed7304814c4e07af68 Merge pull request #5293 from 9rnsr/fix15384 Issue 15384 - assignment is sometimes still accepted as a condition
Comment #4 by github-bugzilla — 2016-03-19T20:21:24Z
Comment #5 by github-bugzilla — 2018-01-03T22:32:03Z
Commit pushed to dmd-cxx at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/9ea575a943ae532743aa085400835e007c4f26c4 fix Issue 15384 - assignment is sometimes still accepted as a condition