December 17, 2022 [Issue 3926] opCast(bool) in classes is bug-prone | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=3926 Iain Buclaw <ibuclaw@gdcproject.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Priority|P2 |P3 -- |
December 19, 2022 [Issue 3926] opCast(bool) in classes is bug-prone | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=3926 RazvanN <razvan.nitu1305@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |razvan.nitu1305@gmail.com Resolution|--- |WONTFIX Severity|normal |enhancement --- Comment #1 from RazvanN <razvan.nitu1305@gmail.com> --- This is an enhancement request as the spec clearly states that for boolean operations only structs will implicitly call opCast: https://dlang.org/spec/operatoroverloading.html#boolean_operators (point 3). Indeed, if a struct is transitioned to a class this is problematic, however, other problems might appear also (for example, equality comparisons). Therefore, I don't think this is a good argument for implementing this and most likely this might silently change the behavior of a lot of code. One solution would be to have a third party tool (like D-Scanner) implement a check for class instances that are used in if conditions and also define an opCast. A warning could be issued then. -- |
Copyright © 1999-2021 by the D Language Foundation