diff --git a/include/grpc/support/port_platform.h b/include/grpc/support/port_platform.h index 1e99dc628e5..bb055465e5f 100644 --- a/include/grpc/support/port_platform.h +++ b/include/grpc/support/port_platform.h @@ -563,29 +563,6 @@ typedef unsigned __int64 uint64_t; #define GRPC_IF_NAMETOINDEX 1 #endif -#ifndef GRPC_MUST_USE_RESULT -#if defined(__GNUC__) && !defined(__MINGW32__) -#define GRPC_MUST_USE_RESULT __attribute__((warn_unused_result)) -#define GPR_ALIGN_STRUCT(n) __attribute__((aligned(n))) -#else -#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 #if defined(__GNUC__) && !defined(__MINGW32__) #define GRPC_UNUSED __attribute__((unused)) @@ -611,6 +588,35 @@ typedef unsigned __int64 uint64_t; #endif #endif /* GPR_HAS_CPP_ATTRIBUTE */ +#if defined(__GNUC__) && !defined(__MINGW32__) +#define GPR_ALIGN_STRUCT(n) __attribute__((aligned(n))) +#else +#define GPR_ALIGN_STRUCT(n) +#endif + +#ifndef GRPC_MUST_USE_RESULT +#if GPR_HAS_CPP_ATTRIBUTE(nodiscard) +#define GRPC_MUST_USE_RESULT [[nodiscard]] +#elif defined(__GNUC__) && !defined(__MINGW32__) +#define GRPC_MUST_USE_RESULT __attribute__((warn_unused_result)) +#else +#define GRPC_MUST_USE_RESULT +#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 GPR_HAS_ATTRIBUTE #ifdef __has_attribute #define GPR_HAS_ATTRIBUTE(a) __has_attribute(a) diff --git a/include/grpcpp/ext/gcp_observability.h b/include/grpcpp/ext/gcp_observability.h index 871b51dce66..b215312c68a 100644 --- a/include/grpcpp/ext/gcp_observability.h +++ b/include/grpcpp/ext/gcp_observability.h @@ -67,7 +67,7 @@ class GcpObservability { // As an implementation detail, this properly initializes the OpenCensus stats // and tracing plugin, so applications do not need to perform any additional // gRPC C++ OpenCensus setup/registration to get GCP Observability for gRPC. - static absl::StatusOr Init() GRPC_MUST_USE_RESULT; + static absl::StatusOr Init(); GcpObservability() = default; // Move constructor and Move-assignment operator. diff --git a/include/grpcpp/impl/call_op_set.h b/include/grpcpp/impl/call_op_set.h index 40d8f5d01c5..48c958a96f6 100644 --- a/include/grpcpp/impl/call_op_set.h +++ b/include/grpcpp/impl/call_op_set.h @@ -290,23 +290,23 @@ class CallOpSendMessage { /// Send \a message using \a options for the write. The \a options are cleared /// after use. template - Status SendMessage(const M& message, - WriteOptions options) GRPC_MUST_USE_RESULT; + GRPC_MUST_USE_RESULT Status SendMessage(const M& message, + WriteOptions options); template - Status SendMessage(const M& message) GRPC_MUST_USE_RESULT; + GRPC_MUST_USE_RESULT Status SendMessage(const M& message); /// Send \a message using \a options for the write. The \a options are cleared /// after use. This form of SendMessage allows gRPC to reference \a message /// beyond the lifetime of SendMessage. template - Status SendMessagePtr(const M* message, - WriteOptions options) GRPC_MUST_USE_RESULT; + GRPC_MUST_USE_RESULT Status SendMessagePtr(const M* message, + WriteOptions options); /// This form of SendMessage allows gRPC to reference \a message beyond the /// lifetime of SendMessage. template - Status SendMessagePtr(const M* message) GRPC_MUST_USE_RESULT; + GRPC_MUST_USE_RESULT Status SendMessagePtr(const M* message); protected: void AddOp(grpc_op* ops, size_t* nops) { diff --git a/src/core/ext/filters/client_channel/dynamic_filters.h b/src/core/ext/filters/client_channel/dynamic_filters.h index 50eafa75aab..87712aa6c5c 100644 --- a/src/core/ext/filters/client_channel/dynamic_filters.h +++ b/src/core/ext/filters/client_channel/dynamic_filters.h @@ -68,9 +68,9 @@ class DynamicFilters : public RefCounted { void SetAfterCallStackDestroy(grpc_closure* closure); // Interface of RefCounted<>. - RefCountedPtr Ref() GRPC_MUST_USE_RESULT; - RefCountedPtr Ref(const DebugLocation& location, - const char* reason) GRPC_MUST_USE_RESULT; + GRPC_MUST_USE_RESULT RefCountedPtr Ref(); + GRPC_MUST_USE_RESULT RefCountedPtr Ref(const DebugLocation& location, + const char* reason); // When refcount drops to 0, destroys itself and the associated call stack, // but does NOT free the memory because it's in the call arena. void Unref(); diff --git a/src/core/ext/filters/client_channel/subchannel.h b/src/core/ext/filters/client_channel/subchannel.h index 033c711bb6c..e66d80fd139 100644 --- a/src/core/ext/filters/client_channel/subchannel.h +++ b/src/core/ext/filters/client_channel/subchannel.h @@ -119,9 +119,9 @@ class SubchannelCall { void SetAfterCallStackDestroy(grpc_closure* closure); // Interface of RefCounted<>. - RefCountedPtr Ref() GRPC_MUST_USE_RESULT; - RefCountedPtr Ref(const DebugLocation& location, - const char* reason) GRPC_MUST_USE_RESULT; + GRPC_MUST_USE_RESULT RefCountedPtr Ref(); + GRPC_MUST_USE_RESULT RefCountedPtr Ref( + const DebugLocation& location, const char* reason); // When refcount drops to 0, destroys itself and the associated call stack, // but does NOT free the memory because it's in the call arena. void Unref(); diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.cc b/src/core/ext/transport/chttp2/server/chttp2_server.cc index 40c1727b9c9..7b4143bfb54 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.cc +++ b/src/core/ext/transport/chttp2/server/chttp2_server.cc @@ -246,13 +246,12 @@ class Chttp2ServerListener : public Server::ListenerInterface { IncrementRefCount(); } - RefCountedPtr Ref() GRPC_MUST_USE_RESULT { + GRPC_MUST_USE_RESULT RefCountedPtr Ref() { IncrementRefCount(); return RefCountedPtr(this); } - RefCountedPtr Ref(const DebugLocation& /* location */, - const char* /* reason */) - GRPC_MUST_USE_RESULT { + GRPC_MUST_USE_RESULT RefCountedPtr Ref( + const DebugLocation& /* location */, const char* /* reason */) { return Ref(); } diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser_table.h b/src/core/ext/transport/chttp2/transport/hpack_parser_table.h index 283a3184b0d..c9839dae771 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser_table.h +++ b/src/core/ext/transport/chttp2/transport/hpack_parser_table.h @@ -71,7 +71,7 @@ class HPackTable { } // add a table entry to the index - bool Add(Memento md) GRPC_MUST_USE_RESULT; + GRPC_MUST_USE_RESULT bool Add(Memento md); void AddLargerThanCurrentTableSize(); // Current entry count in the table. diff --git a/src/core/lib/address_utils/sockaddr_utils.h b/src/core/lib/address_utils/sockaddr_utils.h index 871dfedfc64..32c72bd525f 100644 --- a/src/core/lib/address_utils/sockaddr_utils.h +++ b/src/core/lib/address_utils/sockaddr_utils.h @@ -67,8 +67,8 @@ int grpc_sockaddr_set_port(grpc_resolved_address* addr, int port); // Currently, only the AF_INET, AF_INET6, and AF_UNIX families are recognized. // If the normalize flag is enabled, ::ffff:0.0.0.0/96 IPv6 addresses are // displayed as plain IPv4. -absl::StatusOr grpc_sockaddr_to_string( - const grpc_resolved_address* addr, bool normalize) GRPC_MUST_USE_RESULT; +GRPC_MUST_USE_RESULT absl::StatusOr grpc_sockaddr_to_string( + const grpc_resolved_address* addr, bool normalize); // Returns the URI string corresponding to \a addr absl::StatusOr grpc_sockaddr_to_uri( diff --git a/src/core/lib/channel/channel_args.cc b/src/core/lib/channel/channel_args.cc index 52bcb1d087e..fe8c4761c6c 100644 --- a/src/core/lib/channel/channel_args.cc +++ b/src/core/lib/channel/channel_args.cc @@ -189,25 +189,25 @@ ChannelArgs ChannelArgs::Set(absl::string_view name, int value) const { return Set(name, Value(value)); } -ChannelArgs ChannelArgs::Set(absl::string_view key, Value value) const { - return ChannelArgs(args_.Add(std::string(key), std::move(value))); +ChannelArgs ChannelArgs::Set(absl::string_view name, Value value) const { + return ChannelArgs(args_.Add(std::string(name), std::move(value))); } -ChannelArgs ChannelArgs::Set(absl::string_view key, +ChannelArgs ChannelArgs::Set(absl::string_view name, absl::string_view value) const { - return Set(key, std::string(value)); + return Set(name, std::string(value)); } -ChannelArgs ChannelArgs::Set(absl::string_view key, const char* value) const { - return Set(key, std::string(value)); +ChannelArgs ChannelArgs::Set(absl::string_view name, const char* value) const { + return Set(name, std::string(value)); } -ChannelArgs ChannelArgs::Set(absl::string_view key, std::string value) const { - return Set(key, Value(std::move(value))); +ChannelArgs ChannelArgs::Set(absl::string_view name, std::string value) const { + return Set(name, Value(std::move(value))); } -ChannelArgs ChannelArgs::Remove(absl::string_view key) const { - return ChannelArgs(args_.Remove(key)); +ChannelArgs ChannelArgs::Remove(absl::string_view name) const { + return ChannelArgs(args_.Remove(name)); } ChannelArgs ChannelArgs::RemoveAllKeysWithPrefix( diff --git a/src/core/lib/event_engine/posix_engine/timer.h b/src/core/lib/event_engine/posix_engine/timer.h index c21a03dce10..9c9b220c411 100644 --- a/src/core/lib/event_engine/posix_engine/timer.h +++ b/src/core/lib/event_engine/posix_engine/timer.h @@ -89,7 +89,7 @@ class TimerList { // timer has already fired, or if its closure is currently running. The // closure is guaranteed to run eventually if this method returns false. // Otherwise, this returns true, and the closure will not be run. - bool TimerCancel(Timer* timer) GRPC_MUST_USE_RESULT; + GRPC_MUST_USE_RESULT bool TimerCancel(Timer* timer); // Check for timers to be run, and return them. // Return nullopt if timers could not be checked due to contention with diff --git a/src/core/lib/gprpp/dual_ref_counted.h b/src/core/lib/gprpp/dual_ref_counted.h index e83b27370ca..4fc6ea760da 100644 --- a/src/core/lib/gprpp/dual_ref_counted.h +++ b/src/core/lib/gprpp/dual_ref_counted.h @@ -49,13 +49,13 @@ class DualRefCounted : public Orphanable { public: ~DualRefCounted() override = default; - RefCountedPtr Ref() GRPC_MUST_USE_RESULT { + GRPC_MUST_USE_RESULT RefCountedPtr Ref() { IncrementRefCount(); return RefCountedPtr(static_cast(this)); } - RefCountedPtr Ref(const DebugLocation& location, - const char* reason) GRPC_MUST_USE_RESULT { + GRPC_MUST_USE_RESULT RefCountedPtr Ref(const DebugLocation& location, + const char* reason) { IncrementRefCount(location, reason); return RefCountedPtr(static_cast(this)); } @@ -103,7 +103,7 @@ class DualRefCounted : public Orphanable { WeakUnref(location, reason); } - RefCountedPtr RefIfNonZero() GRPC_MUST_USE_RESULT { + GRPC_MUST_USE_RESULT RefCountedPtr RefIfNonZero() { uint64_t prev_ref_pair = refs_.load(std::memory_order_acquire); do { const uint32_t strong_refs = GetStrongRefs(prev_ref_pair); @@ -121,8 +121,8 @@ class DualRefCounted : public Orphanable { return RefCountedPtr(static_cast(this)); } - RefCountedPtr RefIfNonZero(const DebugLocation& location, - const char* reason) GRPC_MUST_USE_RESULT { + GRPC_MUST_USE_RESULT RefCountedPtr RefIfNonZero( + const DebugLocation& location, const char* reason) { uint64_t prev_ref_pair = refs_.load(std::memory_order_acquire); do { const uint32_t strong_refs = GetStrongRefs(prev_ref_pair); @@ -146,13 +146,13 @@ class DualRefCounted : public Orphanable { return RefCountedPtr(static_cast(this)); } - WeakRefCountedPtr WeakRef() GRPC_MUST_USE_RESULT { + GRPC_MUST_USE_RESULT WeakRefCountedPtr WeakRef() { IncrementWeakRefCount(); return WeakRefCountedPtr(static_cast(this)); } - WeakRefCountedPtr WeakRef(const DebugLocation& location, - const char* reason) GRPC_MUST_USE_RESULT { + GRPC_MUST_USE_RESULT WeakRefCountedPtr WeakRef( + const DebugLocation& location, const char* reason) { IncrementWeakRefCount(location, reason); return WeakRefCountedPtr(static_cast(this)); } diff --git a/src/core/lib/gprpp/orphanable.h b/src/core/lib/gprpp/orphanable.h index a2f24cb54c2..86319429e5c 100644 --- a/src/core/lib/gprpp/orphanable.h +++ b/src/core/lib/gprpp/orphanable.h @@ -87,12 +87,12 @@ class InternallyRefCounted : public Orphanable { : refs_(initial_refcount, trace) {} ~InternallyRefCounted() override = default; - RefCountedPtr Ref() GRPC_MUST_USE_RESULT { + GRPC_MUST_USE_RESULT RefCountedPtr Ref() { IncrementRefCount(); return RefCountedPtr(static_cast(this)); } - RefCountedPtr Ref(const DebugLocation& location, - const char* reason) GRPC_MUST_USE_RESULT { + GRPC_MUST_USE_RESULT RefCountedPtr Ref(const DebugLocation& location, + const char* reason) { IncrementRefCount(location, reason); return RefCountedPtr(static_cast(this)); } diff --git a/src/core/lib/gprpp/ref_counted.h b/src/core/lib/gprpp/ref_counted.h index 96fe288ff6f..66ef0424899 100644 --- a/src/core/lib/gprpp/ref_counted.h +++ b/src/core/lib/gprpp/ref_counted.h @@ -277,13 +277,13 @@ class RefCounted : public Impl { // Note: Depending on the Impl used, this dtor can be implicitly virtual. ~RefCounted() = default; - RefCountedPtr Ref() GRPC_MUST_USE_RESULT { + GRPC_MUST_USE_RESULT RefCountedPtr Ref() { IncrementRefCount(); return RefCountedPtr(static_cast(this)); } - RefCountedPtr Ref(const DebugLocation& location, - const char* reason) GRPC_MUST_USE_RESULT { + GRPC_MUST_USE_RESULT RefCountedPtr Ref(const DebugLocation& location, + const char* reason) { IncrementRefCount(location, reason); return RefCountedPtr(static_cast(this)); } @@ -303,12 +303,12 @@ class RefCounted : public Impl { } } - RefCountedPtr RefIfNonZero() GRPC_MUST_USE_RESULT { + GRPC_MUST_USE_RESULT RefCountedPtr RefIfNonZero() { return RefCountedPtr(refs_.RefIfNonZero() ? static_cast(this) : nullptr); } - RefCountedPtr RefIfNonZero(const DebugLocation& location, - const char* reason) GRPC_MUST_USE_RESULT { + GRPC_MUST_USE_RESULT RefCountedPtr RefIfNonZero( + const DebugLocation& location, const char* reason) { return RefCountedPtr(refs_.RefIfNonZero(location, reason) ? static_cast(this) : nullptr); diff --git a/src/core/lib/gprpp/status_helper.h b/src/core/lib/gprpp/status_helper.h index 3f61c3e1645..536ced385c6 100644 --- a/src/core/lib/gprpp/status_helper.h +++ b/src/core/lib/gprpp/status_helper.h @@ -116,57 +116,58 @@ enum class StatusTimeProperty { }; /// Creates a status with given additional information -absl::Status StatusCreate( - absl::StatusCode code, absl::string_view msg, const DebugLocation& location, - std::vector children) GRPC_MUST_USE_RESULT; +absl::Status StatusCreate(absl::StatusCode code, absl::string_view msg, + const DebugLocation& location, + std::vector children); /// Sets the int property to the status void StatusSetInt(absl::Status* status, StatusIntProperty key, intptr_t value); /// Gets the int property from the status -absl::optional StatusGetInt( - const absl::Status& status, StatusIntProperty key) GRPC_MUST_USE_RESULT; +GRPC_MUST_USE_RESULT +absl::optional StatusGetInt(const absl::Status& status, + StatusIntProperty key); /// Sets the str property to the status void StatusSetStr(absl::Status* status, StatusStrProperty key, absl::string_view value); /// Gets the str property from the status -absl::optional StatusGetStr( - const absl::Status& status, StatusStrProperty key) GRPC_MUST_USE_RESULT; +GRPC_MUST_USE_RESULT absl::optional StatusGetStr( + const absl::Status& status, StatusStrProperty key); /// Sets the time property to the status void StatusSetTime(absl::Status* status, StatusTimeProperty key, absl::Time time); /// Gets the time property from the status -absl::optional StatusGetTime( - const absl::Status& status, StatusTimeProperty key) GRPC_MUST_USE_RESULT; +GRPC_MUST_USE_RESULT absl::optional StatusGetTime( + const absl::Status& status, StatusTimeProperty key); /// Adds a child status to status void StatusAddChild(absl::Status* status, absl::Status child); /// Returns all children status from a status -std::vector StatusGetChildren(absl::Status status) - GRPC_MUST_USE_RESULT; +GRPC_MUST_USE_RESULT std::vector StatusGetChildren( + absl::Status status); /// Returns a string representation from status /// Error status will be like /// STATUS[:MESSAGE] [{PAYLOADS[, children:[CHILDREN-STATUS-LISTS]]}] /// e.g. /// CANCELLATION:SampleMessage {errno:'2021', line:'54', children:[ABORTED]} -std::string StatusToString(const absl::Status& status) GRPC_MUST_USE_RESULT; +GRPC_MUST_USE_RESULT std::string StatusToString(const absl::Status& status); namespace internal { /// Builds a upb message, google_rpc_Status from a status /// This is for internal implementation & test only -google_rpc_Status* StatusToProto(const absl::Status& status, - upb_Arena* arena) GRPC_MUST_USE_RESULT; +GRPC_MUST_USE_RESULT google_rpc_Status* StatusToProto( + const absl::Status& status, upb_Arena* arena); /// Builds a status from a upb message, google_rpc_Status /// This is for internal implementation & test only -absl::Status StatusFromProto(google_rpc_Status* msg) GRPC_MUST_USE_RESULT; +absl::Status StatusFromProto(google_rpc_Status* msg); /// Returns ptr that is allocated in the heap memory and the given status is /// copied into. This ptr can be used to get Status later and should be diff --git a/src/core/lib/http/httpcli.h b/src/core/lib/http/httpcli.h index bcbaa315b92..bfa98a378f6 100644 --- a/src/core/lib/http/httpcli.h +++ b/src/core/lib/http/httpcli.h @@ -100,12 +100,11 @@ class HttpRequest : public InternallyRefCounted { // nullptr is treated as insecure credentials. // TODO(yihuaz): disallow nullptr as a value after unsecure builds // are removed. - static OrphanablePtr Get( + GRPC_MUST_USE_RESULT static OrphanablePtr Get( URI uri, const grpc_channel_args* args, grpc_polling_entity* pollent, const grpc_http_request* request, Timestamp deadline, grpc_closure* on_done, grpc_http_response* response, - RefCountedPtr channel_creds) - GRPC_MUST_USE_RESULT; + RefCountedPtr channel_creds); // Asynchronously perform a HTTP POST. // 'uri' is the target to make the request to. The scheme field is used to @@ -126,12 +125,11 @@ class HttpRequest : public InternallyRefCounted { // TODO(apolcyn): disallow nullptr as a value after unsecure builds // are removed. // Does not support ?var1=val1&var2=val2 in the path. - static OrphanablePtr Post( + GRPC_MUST_USE_RESULT static OrphanablePtr Post( URI uri, const grpc_channel_args* args, grpc_polling_entity* pollent, const grpc_http_request* request, Timestamp deadline, grpc_closure* on_done, grpc_http_response* response, - RefCountedPtr channel_creds) - GRPC_MUST_USE_RESULT; + RefCountedPtr channel_creds); // Asynchronously perform a HTTP PUT. // 'uri' is the target to make the request to. The scheme field is used to @@ -152,12 +150,11 @@ class HttpRequest : public InternallyRefCounted { // TODO(apolcyn): disallow nullptr as a value after unsecure builds // are removed. // Does not support ?var1=val1&var2=val2 in the path. - static OrphanablePtr Put( + GRPC_MUST_USE_RESULT static OrphanablePtr Put( URI uri, const grpc_channel_args* args, grpc_polling_entity* pollent, const grpc_http_request* request, Timestamp deadline, grpc_closure* on_done, grpc_http_response* response, - RefCountedPtr channel_creds) - GRPC_MUST_USE_RESULT; + RefCountedPtr channel_creds); HttpRequest(URI uri, const grpc_slice& request_text, grpc_http_response* response, Timestamp deadline, diff --git a/src/core/lib/iomgr/error.h b/src/core/lib/iomgr/error.h index 79ce199b534..e1bec1b91df 100644 --- a/src/core/lib/iomgr/error.h +++ b/src/core/lib/iomgr/error.h @@ -46,8 +46,7 @@ typedef absl::Status grpc_error_handle; absl::Status grpc_status_create(absl::StatusCode code, absl::string_view msg, const grpc_core::DebugLocation& location, - size_t children_count, - absl::Status* children) GRPC_MUST_USE_RESULT; + size_t children_count, absl::Status* children); // Create an error that references some other errors. #define GRPC_ERROR_CREATE_REFERENCING(desc, errs, count) \ @@ -73,7 +72,7 @@ static absl::Status grpc_status_create_from_vector( grpc_status_create_from_vector(DEBUG_LOCATION, desc, error_list) absl::Status grpc_os_error(const grpc_core::DebugLocation& location, int err, - const char* call_name) GRPC_MUST_USE_RESULT; + const char* call_name); inline absl::Status grpc_assert_never_ok(absl::Status error) { GPR_ASSERT(!error.ok()); @@ -85,7 +84,7 @@ inline absl::Status grpc_assert_never_ok(absl::Status error) { grpc_assert_never_ok(grpc_os_error(DEBUG_LOCATION, err, call_name)) absl::Status grpc_wsa_error(const grpc_core::DebugLocation& location, int err, - absl::string_view call_name) GRPC_MUST_USE_RESULT; + absl::string_view call_name); /// windows only: create an error associated with WSAGetLastError()!=0 #define GRPC_WSA_ERROR(err, call_name) \ @@ -93,14 +92,14 @@ absl::Status grpc_wsa_error(const grpc_core::DebugLocation& location, int err, grpc_error_handle grpc_error_set_int(grpc_error_handle src, grpc_core::StatusIntProperty which, - intptr_t value) GRPC_MUST_USE_RESULT; + intptr_t value); /// It is an error to pass nullptr as `p`. Caller should allocate a phony /// intptr_t for `p`, even if the value of `p` is not used. bool grpc_error_get_int(grpc_error_handle error, grpc_core::StatusIntProperty which, intptr_t* p); -grpc_error_handle grpc_error_set_str( - grpc_error_handle src, grpc_core::StatusStrProperty which, - absl::string_view str) GRPC_MUST_USE_RESULT; +grpc_error_handle grpc_error_set_str(grpc_error_handle src, + grpc_core::StatusStrProperty which, + absl::string_view str); /// Returns false if the specified string is not set. bool grpc_error_get_str(grpc_error_handle error, grpc_core::StatusStrProperty which, std::string* str); @@ -116,8 +115,8 @@ bool grpc_error_get_str(grpc_error_handle error, /// returns absl::OkStatus(). 3) If \a src and \a child point to the same error, /// returns a single reference. (Note that, 2 references should have been /// received to the error in this case.) -grpc_error_handle grpc_error_add_child( - grpc_error_handle src, grpc_error_handle child) GRPC_MUST_USE_RESULT; +grpc_error_handle grpc_error_add_child(grpc_error_handle src, + grpc_error_handle child); bool grpc_log_error(const char* what, grpc_error_handle error, const char* file, int line); diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index e72bb404600..75acbbe8d1d 100644 --- a/src/core/lib/iomgr/ev_poll_posix.cc +++ b/src/core/lib/iomgr/ev_poll_posix.cc @@ -235,7 +235,7 @@ static int poll_deadline_to_millis_timeout(grpc_core::Timestamp deadline); // -- mostly for fd_posix's use. static grpc_error_handle pollset_kick_ext(grpc_pollset* p, grpc_pollset_worker* specific_worker, - uint32_t flags) GRPC_MUST_USE_RESULT; + uint32_t flags); // Return 1 if the pollset has active threads in pollset_work (pollset must // be locked) diff --git a/src/core/lib/iomgr/pollset.h b/src/core/lib/iomgr/pollset.h index b04f71fa376..137a581b91f 100644 --- a/src/core/lib/iomgr/pollset.h +++ b/src/core/lib/iomgr/pollset.h @@ -86,14 +86,13 @@ void grpc_pollset_destroy(grpc_pollset* pollset); // May call grpc_closure_list_run on grpc_closure_list, without holding the // pollset // lock -grpc_error_handle grpc_pollset_work( - grpc_pollset* pollset, grpc_pollset_worker** worker, - grpc_core::Timestamp deadline) GRPC_MUST_USE_RESULT; +grpc_error_handle grpc_pollset_work(grpc_pollset* pollset, + grpc_pollset_worker** worker, + grpc_core::Timestamp deadline); // Break one polling thread out of polling work for this pollset. // If specific_worker is non-NULL, then kick that worker. grpc_error_handle grpc_pollset_kick(grpc_pollset* pollset, - grpc_pollset_worker* specific_worker) - GRPC_MUST_USE_RESULT; + grpc_pollset_worker* specific_worker); #endif // GRPC_SRC_CORE_LIB_IOMGR_POLLSET_H diff --git a/src/core/lib/iomgr/wakeup_fd_posix.h b/src/core/lib/iomgr/wakeup_fd_posix.h index 3c8ed5278bb..329e7ddd710 100644 --- a/src/core/lib/iomgr/wakeup_fd_posix.h +++ b/src/core/lib/iomgr/wakeup_fd_posix.h @@ -81,12 +81,9 @@ extern int grpc_allow_pipe_wakeup_fd; #define GRPC_WAKEUP_FD_GET_READ_FD(fd_info) ((fd_info)->read_fd) -grpc_error_handle grpc_wakeup_fd_init(grpc_wakeup_fd* fd_info) - GRPC_MUST_USE_RESULT; -grpc_error_handle grpc_wakeup_fd_consume_wakeup(grpc_wakeup_fd* fd_info) - GRPC_MUST_USE_RESULT; -grpc_error_handle grpc_wakeup_fd_wakeup(grpc_wakeup_fd* fd_info) - GRPC_MUST_USE_RESULT; +grpc_error_handle grpc_wakeup_fd_init(grpc_wakeup_fd* fd_info); +grpc_error_handle grpc_wakeup_fd_consume_wakeup(grpc_wakeup_fd* fd_info); +grpc_error_handle grpc_wakeup_fd_wakeup(grpc_wakeup_fd* fd_info); void grpc_wakeup_fd_destroy(grpc_wakeup_fd* fd_info); // Defined in some specialized implementation's .c file, or by diff --git a/src/core/lib/promise/party.h b/src/core/lib/promise/party.h index 909ef8e74af..206cbd5af80 100644 --- a/src/core/lib/promise/party.h +++ b/src/core/lib/promise/party.h @@ -384,7 +384,7 @@ class Party : public Activity, private Wakeable { // Should not be called by derived types except as a tail call to the base // class RunParty when overriding this method to add custom context. // Returns true if the party is over. - virtual bool RunParty() GRPC_MUST_USE_RESULT; + GRPC_MUST_USE_RESULT virtual bool RunParty(); bool RefIfNonZero() { return sync_.RefIfNonZero(); } diff --git a/src/core/lib/resource_quota/memory_quota.h b/src/core/lib/resource_quota/memory_quota.h index c6772d897e4..3f264e257cb 100644 --- a/src/core/lib/resource_quota/memory_quota.h +++ b/src/core/lib/resource_quota/memory_quota.h @@ -459,7 +459,7 @@ class GrpcMemoryAllocatorImpl final : public EventEngineMemoryAllocatorImpl { static constexpr size_t kMaxQuotaBufferSize = 1024 * 1024; // Primitive reservation function. - absl::optional TryReserve(MemoryRequest request) GRPC_MUST_USE_RESULT; + GRPC_MUST_USE_RESULT absl::optional TryReserve(MemoryRequest request); // This function may be invoked during a memory release operation. // It will try to return half of our free pool to the quota. void MaybeDonateBack(); diff --git a/src/core/lib/surface/server.h b/src/core/lib/surface/server.h index d635da585b7..ac4624c66b5 100644 --- a/src/core/lib/surface/server.h +++ b/src/core/lib/surface/server.h @@ -420,8 +420,8 @@ class Server : public InternallyRefCounted, } // Returns a notification pointer to wait on if there are requests in-flight, // or null. - Notification* ShutdownUnrefOnShutdownCall() - ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_global_) GRPC_MUST_USE_RESULT { + GRPC_MUST_USE_RESULT Notification* ShutdownUnrefOnShutdownCall() + ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_global_) { if (shutdown_refs_.fetch_sub(1, std::memory_order_acq_rel) == 1) { // There is no request in-flight. MaybeFinishShutdown();