Open Bug 1260617 Opened 9 years ago Updated 3 years ago

Restrict the use of bool operator of Maybe<>

Categories

(Core :: MFBT, defect)

defect

Tracking

()

People

(Reporter: xidorn, Unassigned)

Details

As revealed in bug 1216001 comment 36, operator bool of Maybe could be error prone, especially if T is bool or pointer. I think we should consider restrict the use of operator bool here. Probably we could delete it when T is convertible to bool itself.
Summary: Restrict the use of bool operator of Maybe → Restrict the use of bool operator of Maybe<>
I was nearby, so I'm looking into this... Just a thought: Should we also disable 'operator *()' and 'operator->()' if T is a pointer type? Because these will only remove the Maybe shell and give us a pointer instead of a pointee. (Though presumably most misuses should get caught thanks to the different 'T*' and 'T' types.) A further thought: I know some people hate Maybe's acts-like-a-pointer duck-typing (I personally love it, but I understand why it can be considered bad), so should we discuss just completely removing 'operator bool()', 'operator*()', and 'operator->()' for all types? It would make a lot of things more verbose, but also more obvious and searchable. Note that std::optional also offers this pointer-like duck-typing.
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.