Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-68246

change calls to `boost::optional` members `is_initialized` and `get` (via clang-tidy)

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 6.1.0-rc0
    • 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

            Assignee:
            billy.donahue@mongodb.com Billy Donahue
            Reporter:
            billy.donahue@mongodb.com Billy Donahue
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: