-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
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.