[Issue 3926] opCast(bool) in classes is bug-prone

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Dec 19 15:37:59 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=3926

RazvanN <razvan.nitu1305 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305 at gmail.com
         Resolution|---                         |WONTFIX
           Severity|normal                      |enhancement

--- Comment #1 from RazvanN <razvan.nitu1305 at 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.

--


More information about the Digitalmars-d-bugs mailing list