Bug 8913 – Wrong code in IfStatement condition Expression

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-10-30T06:44:00Z
Last change time
2014-06-12T17:12:33Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
ibuclaw
Blocks
12900

Comments

Comment #0 by ibuclaw — 2012-10-30T06:44:09Z
struct A { char[1] b; } void main() { A c; if (*c.b.ptr) return; return; } The following of type char ==== *c.b.ptr ==== Generates and sends to the backend as type char[1] ==== c.b ==== This is wrong and invalid (non-scalar types cannot be used as boolean types). Regards Iain.
Comment #1 by ibuclaw — 2012-10-30T08:17:21Z
This conversion occurs in PtrExp::optimize. *&c.b -> c.b For static array types, would there be a problem doing this instead? *&c.b -> c.b[0]
Comment #2 by k.hara.pg — 2012-12-18T00:29:55Z
Comment #3 by github-bugzilla — 2013-01-31T04:08:19Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/57f6bdcc3ec10dfc9f7081e7b781d4799e45317f fix Issue 8913 - Wrong code in IfStatement condition Expression Type cast from `e : T[n]` to `T*` should generate `&e[0]`, not `&e`. https://github.com/D-Programming-Language/dmd/commit/62818b3863a14ccc828c1d3623db038170a8c129 Merge pull request #1382 from 9rnsr/fix8913 Issue 8913 - Wrong code in IfStatement condition Expression