-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
Fully Compatible
-
Service Arch 2022-08-08
Update all occurrences of boost::optional's is_initialized or get members.
(comes out of Skunkworks July 2022)
We should prefer using the API that's common between boost::optional and std::optional where we can, and we can in these cases.
- boost::optional has deprecated the is_initialized member, in favor of the std::optional-compatible name has_value. Change all occurrences of is_initialized to has_value.
- boost::optional has a get member, and std::optional does not. The common subset has two choices to get() calls: operator*() and value(). operator*() does exactly what get() does, but has a weird name and may not actually represent the intent of the caller. get has undefined behavior if the object is empty. Change these to value, which is supported by std::optional and throws on empty, making it a safer default choice. get() can be changed to operator*() if the value() behavior is inappropriate.
Future recurrences will be hard to lint on, but easy to clang-tidy on when we can load plugins into clang-tidy. This conversion is done by a clang-tidy plugin in the first place. In the meantime, the clang-tidy plugin can be compiled in.
The plugin: https://github.com/BillyDonahue/mongo_std_optional_migration
- is depended on by
-
SERVER-68376 IDL: don't emit optional get and is_initialized calls
- Closed
- is related to
-
SERVER-26542 Migrate to std::optional
- Backlog
-
SERVER-68121 clang-tool boost::optional -> std::optional migration
- Backlog
- related to
-
SERVER-68247 Support mongo-authored clang-tidy plugins in Evergreen
- Closed