Added GRPC_MUST_USE_RESULT_WHEN_USE_STRICT_WARNING to grpc::Status (#29363)

* Added GRPC_MUST_USE_RESULT_WHEN_USE_STRICT_WARNING to grpc::Status

* Added Comment
pull/29594/head
Esun Kim 3 years ago committed by GitHub
parent fa5598759c
commit c20f10310c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      bazel/copts.bzl
  2. 13
      include/grpc/impl/codegen/port_platform.h
  3. 4
      include/grpcpp/impl/codegen/status.h

@ -57,6 +57,6 @@ GRPC_LLVM_WARNING_FLAGS = [
]
GRPC_DEFAULT_COPTS = select({
"//:use_strict_warning": GRPC_LLVM_WARNING_FLAGS,
"//:use_strict_warning": GRPC_LLVM_WARNING_FLAGS + ["-DUSE_STRICT_WARNING=1"],
"//conditions:default": [],
})

@ -528,6 +528,19 @@ typedef unsigned __int64 uint64_t;
#define GRPC_MUST_USE_RESULT
#define GPR_ALIGN_STRUCT(n)
#endif
#ifdef USE_STRICT_WARNING
/* When building with USE_STRICT_WARNING (which -Werror), types with this
attribute will be treated as annotated with warn_unused_result, enforcing
returned values of this type should be used.
This is added in grpc::Status in mind to address the issue where it always
has this annotation internally but OSS doesn't, sometimes causing internal
build failure. To prevent this, this is added while not introducing
a breaking change to existing user code which may not use returned values
of grpc::Status. */
#define GRPC_MUST_USE_RESULT_WHEN_USE_STRICT_WARNING GRPC_MUST_USE_RESULT
#else
#define GRPC_MUST_USE_RESULT_WHEN_USE_STRICT_WARNING
#endif
#endif
#ifndef GRPC_UNUSED

@ -21,6 +21,8 @@
// IWYU pragma: private, include <grpcpp/support/status.h>
#include <grpc/impl/codegen/port_platform.h>
#include <grpc/impl/codegen/status.h>
#include <grpcpp/impl/codegen/config.h>
#include <grpcpp/impl/codegen/status_code_enum.h>
@ -30,7 +32,7 @@ namespace grpc {
/// Did it work? If it didn't, why?
///
/// See \a grpc::StatusCode for details on the available code and their meaning.
class Status {
class GRPC_MUST_USE_RESULT_WHEN_USE_STRICT_WARNING Status {
public:
/// Construct an OK instance.
Status() : code_(StatusCode::OK) {

Loading…
Cancel
Save