diff options
author | ADAM David Alan Martin <adam.martin@10gen.com> | 2017-06-18 23:22:02 -0400 |
---|---|---|
committer | ADAM David Alan Martin <adam.martin@10gen.com> | 2017-06-18 23:46:57 -0400 |
commit | 9abef6f25aadfd04309cb2219068097f93dc961d (patch) | |
tree | f88c7f183f201813f363d5d68c1a4a76781ca7ef /src/mongo/platform | |
parent | a5f0a84c79b6ce41fef33da920c62be0ecc8f07b (diff) | |
download | mongo-9abef6f25aadfd04309cb2219068097f93dc961d.tar.gz |
SERVER-27244 Status usage compile-time facilities.
There are numerous places in the codebase where `mongo::Status` or
`mongo::StatusWith< T >` objects are returned and never checked.
Many of these are innocuous, but many of them are potentially
severe bugs. This change introduces facilities to permit
compile-time warning of unchecked `Status` and `StatusWith` usage
on clang compilers. It introduces an `ignore` function which is
useful to state that a specific "ignored status" case was
intentional. It not presently an error, in clang builds, to
forget to check a `Status` -- this will come in a later commit.
This also introduces a `transitional_ignore` function, which allows
for easy continual auditing of the codebase for current "whitelisted"
unchecked-status instances. All present "ignored status" cases
have been marked `transitional_ignore`.
Diffstat (limited to 'src/mongo/platform')
-rw-r--r-- | src/mongo/platform/compiler.h | 8 | ||||
-rw-r--r-- | src/mongo/platform/compiler_gcc.h | 3 | ||||
-rw-r--r-- | src/mongo/platform/compiler_msvc.h | 2 |
3 files changed, 13 insertions, 0 deletions
diff --git a/src/mongo/platform/compiler.h b/src/mongo/platform/compiler.h index 59d7de5dbfb..af3e0b20dc3 100644 --- a/src/mongo/platform/compiler.h +++ b/src/mongo/platform/compiler.h @@ -143,8 +143,16 @@ * adversarial inputs, but for some reason the compiler cannot figure this out on its own, for * example after a call to a function that never returns but cannot be labeled with * MONGO_COMPILER_NORETURN. In almost all cases MONGO_UNREACHABLE is preferred. + * + * + * MONGO_WARN_UNUSED_RESULT_CLASS + * + * Tells the compiler that a class defines a type for which checking results is necessary. Types + * thus defined turn functions returning them into "must check results" style functions. Preview + * of the `[[nodiscard]]` C++17 attribute. */ + #if defined(_MSC_VER) #include "mongo/platform/compiler_msvc.h" #elif defined(__GNUC__) diff --git a/src/mongo/platform/compiler_gcc.h b/src/mongo/platform/compiler_gcc.h index cf3b239db35..cf5c6960a86 100644 --- a/src/mongo/platform/compiler_gcc.h +++ b/src/mongo/platform/compiler_gcc.h @@ -42,9 +42,12 @@ // worth it. #define MONGO_COMPILER_COLD_FUNCTION #define MONGO_COMPILER_NORETURN __attribute__((__noreturn__)) +// MONGO_WARN_UNUSED_RESULT is only supported in the semantics we want for classes in Clang, not in GCC. +#define MONGO_WARN_UNUSED_RESULT_CLASS #else #define MONGO_COMPILER_COLD_FUNCTION __attribute__((__cold__)) #define MONGO_COMPILER_NORETURN __attribute__((__noreturn__, __cold__)) +#define MONGO_WARN_UNUSED_RESULT_CLASS #endif #define MONGO_COMPILER_VARIABLE_UNUSED __attribute__((__unused__)) diff --git a/src/mongo/platform/compiler_msvc.h b/src/mongo/platform/compiler_msvc.h index c47372e04bd..e9e2bfa86ef 100644 --- a/src/mongo/platform/compiler_msvc.h +++ b/src/mongo/platform/compiler_msvc.h @@ -50,6 +50,8 @@ #define MONGO_COMPILER_API_EXPORT __declspec(dllexport) #define MONGO_COMPILER_API_IMPORT __declspec(dllimport) +#define MONGO_WARN_UNUSED_RESULT_CLASS + #ifdef _M_IX86 // 32-bit x86 supports multiple of calling conventions. We build supporting the cdecl convention // (most common). By labeling our exported and imported functions as such, we do a small favor to |