fix: implement LWG-4015 to make optional conversions ADL-proof#6102
Conversation
Use _Right._Value instead of *_Right in converting constructors and assignments to avoid ADL-found operator* in the namespace of the source type. Also use _Right._Has_value instead of if(_Right).
optional conversions ADL-proof
This is what the Standard now depicts. I'm not sure if it's detectable here, but given GH 2460, I think we should be careful.
|
I pushed additional test coverage for all of the product code changes, and to make the test actually effective. The templated Finally, I observed that even with the maximally poisonous
So we'd actually be fine saying |
|
I'm mirroring this to the MSVC-internal repo. Please notify me if any further changes are pushed, otherwise no action is required. |
|
Didn't realize the union member is I would've probably got stuck at WG21-N5032 [over.match.oper] and it would have taken me forever to realize that the explicit member function call syntax bypasses ADL. And thanks a lot for pointing to LWG-3969, I don't how I'd have gotten there. |

LWG-4015 identified that LWG-3973's changes introduced ADL vulnerability in
optional's converting constructors and assignment operators. The expressions*_Rightand_STD move(*_Right)onoptional<_Ty2>can be hijacked by ADL-foundoperator*overloads in the namespace of_Ty2.Changed to directly access
_Right._Valueand_Right._Has_value(via friend access), avoiding anyoperator*call and thus any ADL.Added a compile-only test using a deleted non-member
operator*as an ADL trap to verify the fix.fixes: #5871