Message384994
Gregory: Even in a low-level compiled language (say, C++), pretty sure the compiler can't automatically optimize out:
if (x) { }
unless it has sure knowledge of the implementation of operator bool; if operator bool's implementation isn't in the header file, and link time optimization isn't involved, it has to call it to ensure any side-effects it might have are invoked.
It can only bypass the call if it knows the implementation of operator bool and can verify it has no observable side-effects (as-if rule). There are exceptions to the as-if rule for optimizations in special cases (copy elision), but I'm pretty sure operator bool isn't one of them; if the optimizer doesn't know the implementation of operator bool, it must call it just in case it does something weird but critical to the program logic.
Point is, I agree that:
if x:
pass
must evaluate non-constant-literal x for truthiness, no matter how silly that seems (not a huge loss, given very little code should ever actually do that). |
|
Date |
User |
Action |
Args |
2021-01-13 05:07:10 | josh.r | set | recipients:
+ josh.r, gvanrossum, gregory.p.smith, ethan.furman, Mark.Shannon, serhiy.storchaka, Mohamed_Atef, pablogsal, stestagg |
2021-01-13 05:07:10 | josh.r | set | messageid: <1610514430.14.0.689694429657.issue42899@roundup.psfhosted.org> |
2021-01-13 05:07:10 | josh.r | link | issue42899 messages |
2021-01-13 05:07:09 | josh.r | create | |
|