Bug 4931 – Implicit opCast!bool in if statement doesn't work with declarator

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-09-23T20:49:00Z
Last change time
2011-04-26T08:22:35Z
Keywords
patch
Assigned to
nobody
Creator
rsinfu

Attachments

IDFilenameSummaryContent-TypeSize
772ifdecl-implicitbool.patchPatch against dmd r686text/plain1583

Comments

Comment #0 by rsinfu — 2010-09-23T20:49:09Z
Created attachment 772 Patch against dmd r686 If an if statement has a variable declarator, a condition is implicitly converted to bool before its value is assigned to the declared variable. The following code doesn't compile: -------------------- void main() { if (S s = S()) {} // (3) } struct S { bool opCast(T : bool)() { return true; } } -------------------- % dmd -o- -c test.d test.d(3): Error: cannot implicitly convert expression (S().opCast()) of type bool to S
Comment #1 by k.hara.pg — 2011-04-26T08:22:35Z