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

Fix [[nodiscard]] violations under MSVC

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.1.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Server Programmability
    • Fully Compatible
    • ALL
    • Programmability 2024-12-23

      The MONGO_WARN_UNUSED_RESULT_CLASS and MONGO_WARN_UNUSED_RESULT_FUNCTION macros are noops under MSVC, but they're [[nodiscard]] under gcc and clang.

      https://github.com/10gen/mongo/blob/824f352349ec4c1e8d62bdbdbbb3af72b8d6bce8/src/mongo/platform/compiler_msvc.h#L55-L56
      https://github.com/10gen/mongo/blob/824f352349ec4c1e8d62bdbdbbb3af72b8d6bce8/src/mongo/platform/compiler_gcc.h#L62-L63

      This is an important attribute, and it's now supported by msvc, so I tried to make it happen. Several violations were found. Some are in Windows-only code that has not ever had this check enabled, but seems to be incorrect code.

      Some of them are due to the implementation of std::function on the MS standard library, which is really interesting. Under libstdc++, a function returning a Status can be bound to a std::function<void()> and the warning will not trigger, even though there is an ignored Status object there!

      These are all likely to be error handling bugs.

            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: