From decc199ca8472b3e55b9779aafc0c682514b70c7 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Wed, 2 Dec 2020 15:46:58 -0800 Subject: [PATCH] Fix by clang-tidy --- BUILD | 18 ++++++++++ include/grpc/impl/codegen/atm_windows.h | 4 +++ include/grpc/impl/codegen/grpc_types.h | 2 +- include/grpc/impl/codegen/sync_windows.h | 4 +++ include/grpcpp/alarm.h | 6 ++-- include/grpcpp/channel.h | 2 +- include/grpcpp/impl/codegen/call_op_set.h | 21 +++++------ include/grpcpp/impl/codegen/callback_common.h | 1 + include/grpcpp/impl/codegen/client_callback.h | 8 ++--- include/grpcpp/impl/codegen/client_context.h | 2 +- .../grpcpp/impl/codegen/client_unary_call.h | 1 + .../grpcpp/impl/codegen/completion_queue.h | 4 +-- include/grpcpp/impl/codegen/config.h | 4 +-- include/grpcpp/impl/codegen/config_protobuf.h | 1 + include/grpcpp/impl/codegen/core_codegen.h | 9 +++-- .../grpcpp/impl/codegen/delegating_channel.h | 6 +++- .../grpcpp/impl/codegen/intercepted_channel.h | 2 +- .../grpcpp/impl/codegen/interceptor_common.h | 16 ++++----- .../grpcpp/impl/codegen/method_handler_impl.h | 22 ++++++++++++ .../grpcpp/impl/codegen/proto_buffer_reader.h | 6 ++-- .../grpcpp/impl/codegen/proto_buffer_writer.h | 10 +++--- include/grpcpp/impl/codegen/proto_utils.h | 2 +- include/grpcpp/impl/codegen/rpc_method.h | 2 +- include/grpcpp/impl/codegen/server_callback.h | 36 +++++++++---------- .../impl/codegen/server_callback_handlers.h | 8 ++--- include/grpcpp/impl/codegen/server_context.h | 5 +-- .../grpcpp/impl/codegen/server_interface.h | 12 +++---- include/grpcpp/impl/codegen/service_type.h | 2 +- include/grpcpp/resource_quota.h | 2 +- include/grpcpp/security/credentials.h | 4 +-- include/grpcpp/server.h | 2 +- include/grpcpp/support/channel_arguments.h | 2 +- 32 files changed, 139 insertions(+), 87 deletions(-) create mode 100644 include/grpcpp/impl/codegen/method_handler_impl.h diff --git a/BUILD b/BUILD index 95343ebc64d..d2fce9d6fea 100644 --- a/BUILD +++ b/BUILD @@ -344,6 +344,9 @@ grpc_cc_library( grpc_cc_library( name = "grpc++_public_hdrs", hdrs = GRPCXX_PUBLIC_HDRS, + external_deps = [ + "protobuf_headers", + ], ) grpc_cc_library( @@ -367,6 +370,9 @@ grpc_cc_library( "src/cpp/common/tls_credentials_options_util.h", "src/cpp/server/secure_server_credentials.h", ], + external_deps = [ + "protobuf_headers", + ], language = "c++", public_hdrs = GRPCXX_PUBLIC_HDRS, select_deps = { @@ -2257,6 +2263,9 @@ grpc_cc_library( name = "grpc++_base", srcs = GRPCXX_SRCS, hdrs = GRPCXX_HDRS, + external_deps = [ + "protobuf_headers", + ], language = "c++", public_hdrs = GRPCXX_PUBLIC_HDRS, deps = [ @@ -2271,6 +2280,9 @@ grpc_cc_library( name = "grpc++_base_unsecure", srcs = GRPCXX_SRCS, hdrs = GRPCXX_HDRS, + external_deps = [ + "protobuf_headers", + ], language = "c++", public_hdrs = GRPCXX_PUBLIC_HDRS, deps = [ @@ -2379,6 +2391,9 @@ grpc_cc_library( grpc_cc_library( name = "grpc++_codegen_proto", + external_deps = [ + "protobuf_headers", + ], language = "c++", public_hdrs = [ "include/grpc++/impl/codegen/proto_utils.h", @@ -2450,6 +2465,9 @@ grpc_cc_library( srcs = [ "src/cpp/client/channel_test_peer.cc", ], + external_deps = [ + "gtest", + ], public_hdrs = [ "include/grpc++/test/mock_stream.h", "include/grpc++/test/server_context_test_spouse.h", diff --git a/include/grpc/impl/codegen/atm_windows.h b/include/grpc/impl/codegen/atm_windows.h index c016b90095f..36c76ab6721 100644 --- a/include/grpc/impl/codegen/atm_windows.h +++ b/include/grpc/impl/codegen/atm_windows.h @@ -22,6 +22,8 @@ /** Win32 variant of atm_platform.h */ #include +#ifdef GPR_WINDOWS + typedef intptr_t gpr_atm; #define GPR_ATM_MAX INTPTR_MAX #define GPR_ATM_MIN INTPTR_MIN @@ -125,4 +127,6 @@ static __inline gpr_atm gpr_atm_full_xchg(gpr_atm* p, gpr_atm n) { return (gpr_atm)InterlockedExchangePointer((PVOID*)p, (PVOID)n); } +#endif /* GPR_WINDOWS */ + #endif /* GRPC_IMPL_CODEGEN_ATM_WINDOWS_H */ diff --git a/include/grpc/impl/codegen/grpc_types.h b/include/grpc/impl/codegen/grpc_types.h index 379a50f4f9a..d67a9e97458 100644 --- a/include/grpc/impl/codegen/grpc_types.h +++ b/include/grpc/impl/codegen/grpc_types.h @@ -462,7 +462,7 @@ typedef enum grpc_call_error { /** Default send/receive message size limits in bytes. -1 for unlimited. */ /** TODO(roth) Make this match the default receive limit after next release */ -#define GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH -1 +#define GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH (-1) #define GRPC_DEFAULT_MAX_RECV_MESSAGE_LENGTH (4 * 1024 * 1024) /** Write Flags: */ diff --git a/include/grpc/impl/codegen/sync_windows.h b/include/grpc/impl/codegen/sync_windows.h index ba5d5aede0f..f2ff83b303d 100644 --- a/include/grpc/impl/codegen/sync_windows.h +++ b/include/grpc/impl/codegen/sync_windows.h @@ -21,6 +21,8 @@ #include +#ifdef GPR_WINDOWS + #include typedef struct { @@ -33,4 +35,6 @@ typedef CONDITION_VARIABLE gpr_cv; typedef INIT_ONCE gpr_once; #define GPR_ONCE_INIT INIT_ONCE_STATIC_INIT +#endif /* GPR_WINDOWS */ + #endif /* GRPC_IMPL_CODEGEN_SYNC_WINDOWS_H */ diff --git a/include/grpcpp/alarm.h b/include/grpcpp/alarm.h index 96add23e324..1405590c985 100644 --- a/include/grpcpp/alarm.h +++ b/include/grpcpp/alarm.h @@ -38,7 +38,7 @@ class Alarm : private ::grpc::GrpcLibraryCodegen { Alarm(); /// Destroy the given completion queue alarm, cancelling it in the process. - ~Alarm(); + ~Alarm() override; /// DEPRECATED: Create and set a completion queue alarm instance associated to /// \a cq. @@ -66,8 +66,8 @@ class Alarm : private ::grpc::GrpcLibraryCodegen { Alarm& operator=(const Alarm&) = delete; /// Alarms are movable. - Alarm(Alarm&& rhs) : alarm_(rhs.alarm_) { rhs.alarm_ = nullptr; } - Alarm& operator=(Alarm&& rhs) { + Alarm(Alarm&& rhs) noexcept : alarm_(rhs.alarm_) { rhs.alarm_ = nullptr; } + Alarm& operator=(Alarm&& rhs) noexcept { alarm_ = rhs.alarm_; rhs.alarm_ = nullptr; return *this; diff --git a/include/grpcpp/channel.h b/include/grpcpp/channel.h index 88f016c091a..5e67c642a47 100644 --- a/include/grpcpp/channel.h +++ b/include/grpcpp/channel.h @@ -56,7 +56,7 @@ class Channel final : public ::grpc::ChannelInterface, public std::enable_shared_from_this, private ::grpc::GrpcLibraryCodegen { public: - ~Channel(); + ~Channel() override; /// Get the current channel state. If the channel is in IDLE and /// \a try_to_connect is set to true, try to connect. diff --git a/include/grpcpp/impl/codegen/call_op_set.h b/include/grpcpp/impl/codegen/call_op_set.h index 88cfde6253e..dbc8b9b65dc 100644 --- a/include/grpcpp/impl/codegen/call_op_set.h +++ b/include/grpcpp/impl/codegen/call_op_set.h @@ -58,7 +58,7 @@ inline grpc_metadata* FillMetadataArray( return nullptr; } grpc_metadata* metadata_array = - (grpc_metadata*)(g_core_codegen_interface->gpr_malloc( + static_cast(g_core_codegen_interface->gpr_malloc( (*metadata_count) * sizeof(grpc_metadata))); size_t i = 0; for (auto iter = metadata.cbegin(); iter != metadata.cend(); ++iter, ++i) { @@ -234,7 +234,7 @@ class CallOpSendInitialMetadata { grpc_op* op = &ops[(*nops)++]; op->op = GRPC_OP_SEND_INITIAL_METADATA; op->flags = flags_; - op->reserved = NULL; + op->reserved = nullptr; initial_metadata_ = FillMetadataArray(*metadata_map_, &initial_metadata_count_, ""); op->data.send_initial_metadata.count = initial_metadata_count_; @@ -318,7 +318,7 @@ class CallOpSendMessage { grpc_op* op = &ops[(*nops)++]; op->op = GRPC_OP_SEND_MESSAGE; op->flags = write_options_.flags(); - op->reserved = NULL; + op->reserved = nullptr; op->data.send_message.send_message = send_buf_.c_buffer(); // Flags are per-message: clear them after use. write_options_.Clear(); @@ -436,7 +436,7 @@ class CallOpRecvMessage { grpc_op* op = &ops[(*nops)++]; op->op = GRPC_OP_RECV_MESSAGE; op->flags = 0; - op->reserved = NULL; + op->reserved = nullptr; op->data.recv_message.recv_message = recv_buf_.c_buffer_ptr(); } @@ -545,7 +545,7 @@ class CallOpGenericRecvMessage { grpc_op* op = &ops[(*nops)++]; op->op = GRPC_OP_RECV_MESSAGE; op->flags = 0; - op->reserved = NULL; + op->reserved = nullptr; op->data.recv_message.recv_message = recv_buf_.c_buffer_ptr(); } @@ -628,7 +628,7 @@ class CallOpClientSendClose { grpc_op* op = &ops[(*nops)++]; op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; op->flags = 0; - op->reserved = NULL; + op->reserved = nullptr; } void FinishOp(bool* /*status*/) { send_ = false; } @@ -680,7 +680,7 @@ class CallOpServerSendStatus { op->data.send_status_from_server.status_details = send_error_message_.empty() ? nullptr : &error_message_slice_; op->flags = 0; - op->reserved = NULL; + op->reserved = nullptr; } void FinishOp(bool* /*status*/) { @@ -734,7 +734,7 @@ class CallOpRecvInitialMetadata { op->op = GRPC_OP_RECV_INITIAL_METADATA; op->data.recv_initial_metadata.recv_initial_metadata = metadata_map_->arr(); op->flags = 0; - op->reserved = NULL; + op->reserved = nullptr; } void FinishOp(bool* /*status*/) { @@ -788,7 +788,7 @@ class CallOpClientRecvStatus { op->data.recv_status_on_client.status_details = &error_message_; op->data.recv_status_on_client.error_string = &debug_error_string_; op->flags = 0; - op->reserved = NULL; + op->reserved = nullptr; } void FinishOp(bool* /*status*/) { @@ -806,7 +806,8 @@ class CallOpClientRecvStatus { metadata_map_->GetBinaryErrorDetails()); if (debug_error_string_ != nullptr) { client_context_->set_debug_error_string(debug_error_string_); - g_core_codegen_interface->gpr_free((void*)debug_error_string_); + g_core_codegen_interface->gpr_free( + const_cast(debug_error_string_)); } } // TODO(soheil): Find callers that set debug string even for status OK, diff --git a/include/grpcpp/impl/codegen/callback_common.h b/include/grpcpp/impl/codegen/callback_common.h index aa3bd26e1c5..040c5d5c981 100644 --- a/include/grpcpp/impl/codegen/callback_common.h +++ b/include/grpcpp/impl/codegen/callback_common.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include diff --git a/include/grpcpp/impl/codegen/client_callback.h b/include/grpcpp/impl/codegen/client_callback.h index f2ddaba07b8..77bc885ac59 100644 --- a/include/grpcpp/impl/codegen/client_callback.h +++ b/include/grpcpp/impl/codegen/client_callback.h @@ -251,7 +251,7 @@ class ClientBidiReactor : public internal::ClientReactor { /// not deleted or modified until OnWriteDone is called. /// \param[in] options The WriteOptions to use for writing this message void StartWrite(const Request* req, ::grpc::WriteOptions options) { - stream_->Write(req, std::move(options)); + stream_->Write(req, options); } /// Initiate/post a write operation with specified options and an indication @@ -264,7 +264,7 @@ class ClientBidiReactor : public internal::ClientReactor { /// not deleted or modified until OnWriteDone is called. /// \param[in] options The WriteOptions to use for writing this message void StartWriteLast(const Request* req, ::grpc::WriteOptions options) { - StartWrite(req, std::move(options.set_last_message())); + StartWrite(req, options.set_last_message()); } /// Indicate that the RPC will have no more write operations. This can only be @@ -391,10 +391,10 @@ class ClientWriteReactor : public internal::ClientReactor { StartWrite(req, ::grpc::WriteOptions()); } void StartWrite(const Request* req, ::grpc::WriteOptions options) { - writer_->Write(req, std::move(options)); + writer_->Write(req, options); } void StartWriteLast(const Request* req, ::grpc::WriteOptions options) { - StartWrite(req, std::move(options.set_last_message())); + StartWrite(req, options.set_last_message()); } void StartWritesDone() { writer_->WritesDone(); } diff --git a/include/grpcpp/impl/codegen/client_context.h b/include/grpcpp/impl/codegen/client_context.h index 8a0bd62bbaf..acf1d85bdf1 100644 --- a/include/grpcpp/impl/codegen/client_context.h +++ b/include/grpcpp/impl/codegen/client_context.h @@ -311,7 +311,7 @@ class ClientContext { /// /// \see grpc::AuthContext. std::shared_ptr auth_context() const { - if (auth_context_.get() == nullptr) { + if (auth_context_ == nullptr) { auth_context_ = grpc::CreateAuthContext(call_); } return auth_context_; diff --git a/include/grpcpp/impl/codegen/client_unary_call.h b/include/grpcpp/impl/codegen/client_unary_call.h index b2430aded67..d41ea1ad2d4 100644 --- a/include/grpcpp/impl/codegen/client_unary_call.h +++ b/include/grpcpp/impl/codegen/client_unary_call.h @@ -20,6 +20,7 @@ #define GRPCPP_IMPL_CODEGEN_CLIENT_UNARY_CALL_H #include +#include #include #include #include diff --git a/include/grpcpp/impl/codegen/completion_queue.h b/include/grpcpp/impl/codegen/completion_queue.h index 0234951ca7b..554f4b18db5 100644 --- a/include/grpcpp/impl/codegen/completion_queue.h +++ b/include/grpcpp/impl/codegen/completion_queue.h @@ -114,7 +114,7 @@ class CompletionQueue : private ::grpc::GrpcLibraryCodegen { explicit CompletionQueue(grpc_completion_queue* take); /// Destructor. Destroys the owned wrapped completion queue / instance. - ~CompletionQueue() { + ~CompletionQueue() override { ::grpc::g_core_codegen_interface->grpc_completion_queue_destroy(cq_); } @@ -247,7 +247,7 @@ class CompletionQueue : private ::grpc::GrpcLibraryCodegen { cq_ = ::grpc::g_core_codegen_interface->grpc_completion_queue_create( ::grpc::g_core_codegen_interface->grpc_completion_queue_factory_lookup( &attributes), - &attributes, NULL); + &attributes, nullptr); InitialAvalanching(); // reserve this for the future shutdown } diff --git a/include/grpcpp/impl/codegen/config.h b/include/grpcpp/impl/codegen/config.h index 7c398d14aaa..0a8a9c139ca 100644 --- a/include/grpcpp/impl/codegen/config.h +++ b/include/grpcpp/impl/codegen/config.h @@ -36,8 +36,8 @@ namespace grpc { // Using grpc::string and grpc::to_string is discouraged in favor of // std::string and std::to_string. This is only for legacy code using // them explictly. -using std::string; // deprecated -using std::to_string; // deprecated +using std::string; // deprecated // NOLINT(misc-unused-using-decls) +using std::to_string; // deprecated // NOLINT(misc-unused-using-decls) } // namespace grpc diff --git a/include/grpcpp/impl/codegen/config_protobuf.h b/include/grpcpp/impl/codegen/config_protobuf.h index c4012fb00c9..d6f236b2ee5 100644 --- a/include/grpcpp/impl/codegen/config_protobuf.h +++ b/include/grpcpp/impl/codegen/config_protobuf.h @@ -90,6 +90,7 @@ namespace util { typedef GRPC_CUSTOM_UTIL_STATUS Status; } // namespace util +// NOLINTNEXTLINE(misc-unused-alias-decls) namespace json = GRPC_CUSTOM_JSONUTIL; namespace io { diff --git a/include/grpcpp/impl/codegen/core_codegen.h b/include/grpcpp/impl/codegen/core_codegen.h index 50c8da4ffe7..df2a03cd259 100644 --- a/include/grpcpp/impl/codegen/core_codegen.h +++ b/include/grpcpp/impl/codegen/core_codegen.h @@ -31,10 +31,9 @@ namespace grpc { /// Implementation of the core codegen interface. class CoreCodegen final : public CoreCodegenInterface { private: - virtual const grpc_completion_queue_factory* - grpc_completion_queue_factory_lookup( + const grpc_completion_queue_factory* grpc_completion_queue_factory_lookup( const grpc_completion_queue_attributes* attributes) override; - virtual grpc_completion_queue* grpc_completion_queue_create( + grpc_completion_queue* grpc_completion_queue_create( const grpc_completion_queue_factory* factory, const grpc_completion_queue_attributes* attributes, void* reserved) override; @@ -115,8 +114,8 @@ class CoreCodegen final : public CoreCodegenInterface { gpr_timespec gpr_inf_future(gpr_clock_type type) override; gpr_timespec gpr_time_0(gpr_clock_type type) override; - virtual const Status& ok() override; - virtual const Status& cancelled() override; + const Status& ok() override; + const Status& cancelled() override; void assert_fail(const char* failed_assertion, const char* file, int line) override; diff --git a/include/grpcpp/impl/codegen/delegating_channel.h b/include/grpcpp/impl/codegen/delegating_channel.h index 1a3bbd3349a..85d46d9f96e 100644 --- a/include/grpcpp/impl/codegen/delegating_channel.h +++ b/include/grpcpp/impl/codegen/delegating_channel.h @@ -19,12 +19,16 @@ #ifndef GRPCPP_IMPL_CODEGEN_DELEGATING_CHANNEL_H #define GRPCPP_IMPL_CODEGEN_DELEGATING_CHANNEL_H +#include + +#include + namespace grpc { namespace experimental { class DelegatingChannel : public ::grpc::ChannelInterface { public: - virtual ~DelegatingChannel() {} + ~DelegatingChannel() override {} DelegatingChannel(std::shared_ptr<::grpc::ChannelInterface> delegate_channel) : delegate_channel_(delegate_channel) {} diff --git a/include/grpcpp/impl/codegen/intercepted_channel.h b/include/grpcpp/impl/codegen/intercepted_channel.h index c729970ca88..e3a4c8e7680 100644 --- a/include/grpcpp/impl/codegen/intercepted_channel.h +++ b/include/grpcpp/impl/codegen/intercepted_channel.h @@ -34,7 +34,7 @@ class InterceptorBatchMethodsImpl; /// see the RPC. class InterceptedChannel : public ChannelInterface { public: - virtual ~InterceptedChannel() { channel_ = nullptr; } + ~InterceptedChannel() override { channel_ = nullptr; } /// Get the current channel state. If the channel is in IDLE and /// \a try_to_connect is set to true, try to connect. diff --git a/include/grpcpp/impl/codegen/interceptor_common.h b/include/grpcpp/impl/codegen/interceptor_common.h index b6a9fc3abb2..520d981459f 100644 --- a/include/grpcpp/impl/codegen/interceptor_common.h +++ b/include/grpcpp/impl/codegen/interceptor_common.h @@ -45,7 +45,7 @@ class InterceptorBatchMethodsImpl } } - ~InterceptorBatchMethodsImpl() {} + ~InterceptorBatchMethodsImpl() override {} bool QueryInterceptionHookPoint( experimental::InterceptionHookPoints type) override { @@ -223,7 +223,7 @@ class InterceptorBatchMethodsImpl bool InterceptorsListEmpty() { auto* client_rpc_info = call_->client_rpc_info(); if (client_rpc_info != nullptr) { - if (client_rpc_info->interceptors_.size() == 0) { + if (client_rpc_info->interceptors_.empty()) { return true; } else { return false; @@ -231,8 +231,7 @@ class InterceptorBatchMethodsImpl } auto* server_rpc_info = call_->server_rpc_info(); - if (server_rpc_info == nullptr || - server_rpc_info->interceptors_.size() == 0) { + if (server_rpc_info == nullptr || server_rpc_info->interceptors_.empty()) { return true; } return false; @@ -247,7 +246,7 @@ class InterceptorBatchMethodsImpl GPR_CODEGEN_ASSERT(ops_); auto* client_rpc_info = call_->client_rpc_info(); if (client_rpc_info != nullptr) { - if (client_rpc_info->interceptors_.size() == 0) { + if (client_rpc_info->interceptors_.empty()) { return true; } else { RunClientInterceptors(); @@ -256,8 +255,7 @@ class InterceptorBatchMethodsImpl } auto* server_rpc_info = call_->server_rpc_info(); - if (server_rpc_info == nullptr || - server_rpc_info->interceptors_.size() == 0) { + if (server_rpc_info == nullptr || server_rpc_info->interceptors_.empty()) { return true; } RunServerInterceptors(); @@ -273,8 +271,7 @@ class InterceptorBatchMethodsImpl GPR_CODEGEN_ASSERT(reverse_ == true); GPR_CODEGEN_ASSERT(call_->client_rpc_info() == nullptr); auto* server_rpc_info = call_->server_rpc_info(); - if (server_rpc_info == nullptr || - server_rpc_info->interceptors_.size() == 0) { + if (server_rpc_info == nullptr || server_rpc_info->interceptors_.empty()) { return true; } callback_ = std::move(f); @@ -489,7 +486,6 @@ class CancelInterceptorBatchMethods GPR_CODEGEN_ASSERT(false && "It is illegal to call ModifySendStatus on a method " "which has a Cancel notification"); - return; } std::multimap* GetSendTrailingMetadata() override { diff --git a/include/grpcpp/impl/codegen/method_handler_impl.h b/include/grpcpp/impl/codegen/method_handler_impl.h new file mode 100644 index 00000000000..cc88a135ca2 --- /dev/null +++ b/include/grpcpp/impl/codegen/method_handler_impl.h @@ -0,0 +1,22 @@ +/* + * + * Copyright 2018 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPCPP_IMPL_CODEGEN_METHOD_HANDLER_IMPL_H +#define GRPCPP_IMPL_CODEGEN_METHOD_HANDLER_IMPL_H + +#endif // GRPCPP_IMPL_CODEGEN_METHOD_HANDLER_IMPL_H diff --git a/include/grpcpp/impl/codegen/proto_buffer_reader.h b/include/grpcpp/impl/codegen/proto_buffer_reader.h index 487471290d9..d25b79a4027 100644 --- a/include/grpcpp/impl/codegen/proto_buffer_reader.h +++ b/include/grpcpp/impl/codegen/proto_buffer_reader.h @@ -59,7 +59,7 @@ class ProtoBufferReader : public ::grpc::protobuf::io::ZeroCopyInputStream { } } - ~ProtoBufferReader() { + ~ProtoBufferReader() override { if (status_.ok()) { g_core_codegen_interface->grpc_byte_buffer_reader_destroy(&reader_); } @@ -76,7 +76,7 @@ class ProtoBufferReader : public ::grpc::protobuf::io::ZeroCopyInputStream { *data = GRPC_SLICE_START_PTR(*slice_) + GRPC_SLICE_LENGTH(*slice_) - backup_count_; GPR_CODEGEN_ASSERT(backup_count_ <= INT_MAX); - *size = (int)backup_count_; + *size = static_cast(backup_count_); backup_count_ = 0; return true; } @@ -88,7 +88,7 @@ class ProtoBufferReader : public ::grpc::protobuf::io::ZeroCopyInputStream { *data = GRPC_SLICE_START_PTR(*slice_); // On win x64, int is only 32bit GPR_CODEGEN_ASSERT(GRPC_SLICE_LENGTH(*slice_) <= INT_MAX); - byte_count_ += * size = (int)GRPC_SLICE_LENGTH(*slice_); + byte_count_ += * size = static_cast(GRPC_SLICE_LENGTH(*slice_)); return true; } diff --git a/include/grpcpp/impl/codegen/proto_buffer_writer.h b/include/grpcpp/impl/codegen/proto_buffer_writer.h index 0af4616e508..cd9d70c5a56 100644 --- a/include/grpcpp/impl/codegen/proto_buffer_writer.h +++ b/include/grpcpp/impl/codegen/proto_buffer_writer.h @@ -65,12 +65,12 @@ class ProtoBufferWriter : public ::grpc::protobuf::io::ZeroCopyOutputStream { GPR_CODEGEN_ASSERT(!byte_buffer->Valid()); /// Create an empty raw byte buffer and look at its underlying slice buffer grpc_byte_buffer* bp = - g_core_codegen_interface->grpc_raw_byte_buffer_create(NULL, 0); + g_core_codegen_interface->grpc_raw_byte_buffer_create(nullptr, 0); byte_buffer->set_buffer(bp); slice_buffer_ = &bp->data.raw.slice_buffer; } - ~ProtoBufferWriter() { + ~ProtoBufferWriter() override { if (have_backup_) { g_core_codegen_interface->grpc_slice_unref(backup_slice_); } @@ -107,7 +107,7 @@ class ProtoBufferWriter : public ::grpc::protobuf::io::ZeroCopyOutputStream { *data = GRPC_SLICE_START_PTR(slice_); // On win x64, int is only 32bit GPR_CODEGEN_ASSERT(GRPC_SLICE_LENGTH(slice_) <= INT_MAX); - byte_count_ += * size = (int)GRPC_SLICE_LENGTH(slice_); + byte_count_ += * size = static_cast(GRPC_SLICE_LENGTH(slice_)); g_core_codegen_interface->grpc_slice_buffer_add(slice_buffer_, slice_); return true; } @@ -122,7 +122,7 @@ class ProtoBufferWriter : public ::grpc::protobuf::io::ZeroCopyOutputStream { /// 4. Mark that we still have the remaining part (for later use/unref) GPR_CODEGEN_ASSERT(count <= static_cast(GRPC_SLICE_LENGTH(slice_))); g_core_codegen_interface->grpc_slice_buffer_pop(slice_buffer_); - if ((size_t)count == GRPC_SLICE_LENGTH(slice_)) { + if (static_cast(count) == GRPC_SLICE_LENGTH(slice_)) { backup_slice_ = slice_; } else { backup_slice_ = g_core_codegen_interface->grpc_slice_split_tail( @@ -133,7 +133,7 @@ class ProtoBufferWriter : public ::grpc::protobuf::io::ZeroCopyOutputStream { // on a following Next() call, a reference will be returned to this slice // via GRPC_SLICE_START_PTR, which will not be an address held by // slice_buffer_. - have_backup_ = backup_slice_.refcount != NULL; + have_backup_ = backup_slice_.refcount != nullptr; byte_count_ -= count; } diff --git a/include/grpcpp/impl/codegen/proto_utils.h b/include/grpcpp/impl/codegen/proto_utils.h index 2df49040d19..7f5c6e9a99d 100644 --- a/include/grpcpp/impl/codegen/proto_utils.h +++ b/include/grpcpp/impl/codegen/proto_utils.h @@ -50,7 +50,7 @@ Status GenericSerialize(const grpc::protobuf::MessageLite& msg, ByteBuffer* bb, "::protobuf::io::ZeroCopyOutputStream"); *own_buffer = true; int byte_size = static_cast(msg.ByteSizeLong()); - if ((size_t)byte_size <= GRPC_SLICE_INLINED_SIZE) { + if (static_cast(byte_size) <= GRPC_SLICE_INLINED_SIZE) { Slice slice(byte_size); // We serialize directly into the allocated slices memory GPR_CODEGEN_ASSERT(slice.end() == msg.SerializeWithCachedSizesToArray( diff --git a/include/grpcpp/impl/codegen/rpc_method.h b/include/grpcpp/impl/codegen/rpc_method.h index 9dcde954f1d..394a29b8374 100644 --- a/include/grpcpp/impl/codegen/rpc_method.h +++ b/include/grpcpp/impl/codegen/rpc_method.h @@ -36,7 +36,7 @@ class RpcMethod { }; RpcMethod(const char* name, RpcType type) - : name_(name), method_type_(type), channel_tag_(NULL) {} + : name_(name), method_type_(type), channel_tag_(nullptr) {} RpcMethod(const char* name, RpcType type, const std::shared_ptr& channel) diff --git a/include/grpcpp/impl/codegen/server_callback.h b/include/grpcpp/impl/codegen/server_callback.h index 08d1666691e..9dda984a729 100644 --- a/include/grpcpp/impl/codegen/server_callback.h +++ b/include/grpcpp/impl/codegen/server_callback.h @@ -190,7 +190,7 @@ class ServerBidiReactor; // the API. class ServerCallbackUnary : public internal::ServerCallbackCall { public: - virtual ~ServerCallbackUnary() {} + ~ServerCallbackUnary() override {} virtual void Finish(::grpc::Status s) = 0; virtual void SendInitialMetadata() = 0; @@ -206,7 +206,7 @@ class ServerCallbackUnary : public internal::ServerCallbackCall { template class ServerCallbackReader : public internal::ServerCallbackCall { public: - virtual ~ServerCallbackReader() {} + ~ServerCallbackReader() override {} virtual void Finish(::grpc::Status s) = 0; virtual void SendInitialMetadata() = 0; virtual void Read(Request* msg) = 0; @@ -220,7 +220,7 @@ class ServerCallbackReader : public internal::ServerCallbackCall { template class ServerCallbackWriter : public internal::ServerCallbackCall { public: - virtual ~ServerCallbackWriter() {} + ~ServerCallbackWriter() override {} virtual void Finish(::grpc::Status s) = 0; virtual void SendInitialMetadata() = 0; @@ -237,7 +237,7 @@ class ServerCallbackWriter : public internal::ServerCallbackCall { template class ServerCallbackReaderWriter : public internal::ServerCallbackCall { public: - virtual ~ServerCallbackReaderWriter() {} + ~ServerCallbackReaderWriter() override {} virtual void Finish(::grpc::Status s) = 0; virtual void SendInitialMetadata() = 0; @@ -268,7 +268,7 @@ class ServerBidiReactor : public internal::ServerReactor { // TODO(vjpai): Switch to default constructor and default initializer when // gcc-4.x is no longer supported ServerBidiReactor() : stream_(nullptr) {} - ~ServerBidiReactor() = default; + ~ServerBidiReactor() override = default; /// Send any initial metadata stored in the RPC context. If not invoked, /// any initial metadata will be passed along with the first Write or the @@ -328,11 +328,11 @@ class ServerBidiReactor : public internal::ServerReactor { stream = stream_.load(std::memory_order_relaxed); if (stream == nullptr) { backlog_.write_wanted = resp; - backlog_.write_options_wanted = std::move(options); + backlog_.write_options_wanted = options; return; } } - stream->Write(resp, std::move(options)); + stream->Write(resp, options); } /// Initiate a write operation with specified options and final RPC Status, @@ -358,12 +358,12 @@ class ServerBidiReactor : public internal::ServerReactor { if (stream == nullptr) { backlog_.write_and_finish_wanted = true; backlog_.write_wanted = resp; - backlog_.write_options_wanted = std::move(options); + backlog_.write_options_wanted = options; backlog_.status_wanted = std::move(s); return; } } - stream->WriteAndFinish(resp, std::move(options), std::move(s)); + stream->WriteAndFinish(resp, options, std::move(s)); } /// Inform system of a planned write operation with specified options, but @@ -375,7 +375,7 @@ class ServerBidiReactor : public internal::ServerReactor { /// not deleted or modified until OnWriteDone is called. /// \param[in] options The WriteOptions to use for writing this message void StartWriteLast(const Response* resp, ::grpc::WriteOptions options) { - StartWrite(resp, std::move(options.set_last_message())); + StartWrite(resp, options.set_last_message()); } /// Indicate that the stream is to be finished and the trailing metadata and @@ -484,7 +484,7 @@ template class ServerReadReactor : public internal::ServerReactor { public: ServerReadReactor() : reader_(nullptr) {} - ~ServerReadReactor() = default; + ~ServerReadReactor() override = default; /// The following operation initiations are exactly like ServerBidiReactor. void StartSendInitialMetadata() { @@ -571,7 +571,7 @@ template class ServerWriteReactor : public internal::ServerReactor { public: ServerWriteReactor() : writer_(nullptr) {} - ~ServerWriteReactor() = default; + ~ServerWriteReactor() override = default; /// The following operation initiations are exactly like ServerBidiReactor. void StartSendInitialMetadata() { @@ -598,11 +598,11 @@ class ServerWriteReactor : public internal::ServerReactor { writer = writer_.load(std::memory_order_relaxed); if (writer == nullptr) { backlog_.write_wanted = resp; - backlog_.write_options_wanted = std::move(options); + backlog_.write_options_wanted = options; return; } } - writer->Write(resp, std::move(options)); + writer->Write(resp, options); } void StartWriteAndFinish(const Response* resp, ::grpc::WriteOptions options, ::grpc::Status s) { @@ -614,15 +614,15 @@ class ServerWriteReactor : public internal::ServerReactor { if (writer == nullptr) { backlog_.write_and_finish_wanted = true; backlog_.write_wanted = resp; - backlog_.write_options_wanted = std::move(options); + backlog_.write_options_wanted = options; backlog_.status_wanted = std::move(s); return; } } - writer->WriteAndFinish(resp, std::move(options), std::move(s)); + writer->WriteAndFinish(resp, options, std::move(s)); } void StartWriteLast(const Response* resp, ::grpc::WriteOptions options) { - StartWrite(resp, std::move(options.set_last_message())); + StartWrite(resp, options.set_last_message()); } void Finish(::grpc::Status s) { ServerCallbackWriter* writer = @@ -688,7 +688,7 @@ class ServerWriteReactor : public internal::ServerReactor { class ServerUnaryReactor : public internal::ServerReactor { public: ServerUnaryReactor() : call_(nullptr) {} - ~ServerUnaryReactor() = default; + ~ServerUnaryReactor() override = default; /// StartSendInitialMetadata is exactly like ServerBidiReactor. void StartSendInitialMetadata() { diff --git a/include/grpcpp/impl/codegen/server_callback_handlers.h b/include/grpcpp/impl/codegen/server_callback_handlers.h index 9cee8e945f5..4815cb4e7ce 100644 --- a/include/grpcpp/impl/codegen/server_callback_handlers.h +++ b/include/grpcpp/impl/codegen/server_callback_handlers.h @@ -53,7 +53,7 @@ class CallbackUnaryHandler : public ::grpc::internal::MethodHandler { param.call->call(), sizeof(ServerCallbackUnaryImpl))) ServerCallbackUnaryImpl( static_cast<::grpc::CallbackServerContext*>(param.server_context), - param.call, allocator_state, std::move(param.call_requester)); + param.call, allocator_state, param.call_requester); param.server_context->BeginCompletionOp( param.call, [call](bool) { call->MaybeDone(); }, call); @@ -266,7 +266,7 @@ class CallbackClientStreamingHandler : public ::grpc::internal::MethodHandler { param.call->call(), sizeof(ServerCallbackReaderImpl))) ServerCallbackReaderImpl( static_cast<::grpc::CallbackServerContext*>(param.server_context), - param.call, std::move(param.call_requester)); + param.call, param.call_requester); // Inlineable OnDone can be false in the CompletionOp callback because there // is no read reactor that has an inlineable OnDone; this only applies to // the DefaultReactor (which is unary). @@ -453,7 +453,7 @@ class CallbackServerStreamingHandler : public ::grpc::internal::MethodHandler { ServerCallbackWriterImpl( static_cast<::grpc::CallbackServerContext*>(param.server_context), param.call, static_cast(param.request), - std::move(param.call_requester)); + param.call_requester); // Inlineable OnDone can be false in the CompletionOp callback because there // is no write reactor that has an inlineable OnDone; this only applies to // the DefaultReactor (which is unary). @@ -673,7 +673,7 @@ class CallbackBidiHandler : public ::grpc::internal::MethodHandler { param.call->call(), sizeof(ServerCallbackReaderWriterImpl))) ServerCallbackReaderWriterImpl( static_cast<::grpc::CallbackServerContext*>(param.server_context), - param.call, std::move(param.call_requester)); + param.call, param.call_requester); // Inlineable OnDone can be false in the CompletionOp callback because there // is no bidi reactor that has an inlineable OnDone; this only applies to // the DefaultReactor (which is unary). diff --git a/include/grpcpp/impl/codegen/server_context.h b/include/grpcpp/impl/codegen/server_context.h index 56dcb61eec2..5a62873ec87 100644 --- a/include/grpcpp/impl/codegen/server_context.h +++ b/include/grpcpp/impl/codegen/server_context.h @@ -265,7 +265,7 @@ class ServerContextBase { /// /// \see grpc::AuthContext. std::shared_ptr auth_context() const { - if (auth_context_.get() == nullptr) { + if (auth_context_ == nullptr) { auth_context_ = ::grpc::CreateAuthContext(call_.call); } return auth_context_; @@ -415,7 +415,7 @@ class ServerContextBase { const char* method, ::grpc::internal::RpcMethod::RpcType type, const std::vector>& creators) { - if (creators.size() != 0) { + if (!creators.empty()) { rpc_info_ = new ::grpc::experimental::ServerRpcInfo(this, method, type); rpc_info_->RegisterInterceptors(creators); } @@ -476,6 +476,7 @@ class ServerContextBase { }; void SetupTestDefaultReactor(std::function func) { + // NOLINTNEXTLINE(modernize-make-unique) test_unary_.reset(new TestServerCallbackUnary(this, std::move(func))); } bool test_status_set() const { diff --git a/include/grpcpp/impl/codegen/server_interface.h b/include/grpcpp/impl/codegen/server_interface.h index fef2dc7edfa..c4398f4bcf5 100644 --- a/include/grpcpp/impl/codegen/server_interface.h +++ b/include/grpcpp/impl/codegen/server_interface.h @@ -64,7 +64,7 @@ class ServerInterceptorFactoryInterface; class ServerInterface : public internal::CallHook { public: - virtual ~ServerInterface() {} + ~ServerInterface() override {} /// \a Shutdown does the following things: /// @@ -186,8 +186,8 @@ class ServerInterface : public internal::CallHook { virtual grpc_server* server() = 0; - virtual void PerformOpsOnCall(internal::CallOpSetInterface* ops, - internal::Call* call) = 0; + void PerformOpsOnCall(internal::CallOpSetInterface* ops, + internal::Call* call) override = 0; class BaseAsyncRequest : public internal::CompletionQueueTag { public: @@ -196,7 +196,7 @@ class ServerInterface : public internal::CallHook { ::grpc::CompletionQueue* call_cq, ::grpc::ServerCompletionQueue* notification_cq, void* tag, bool delete_on_finalize); - virtual ~BaseAsyncRequest(); + ~BaseAsyncRequest() override; bool FinalizeResult(void** tag, bool* status) override; @@ -228,7 +228,7 @@ class ServerInterface : public internal::CallHook { void* tag, const char* name, internal::RpcMethod::RpcType type); - virtual bool FinalizeResult(void** tag, bool* status) override { + bool FinalizeResult(void** tag, bool* status) override { /* If we are done intercepting, then there is nothing more for us to do */ if (done_intercepting_) { return BaseAsyncRequest::FinalizeResult(tag, status); @@ -283,7 +283,7 @@ class ServerInterface : public internal::CallHook { notification_cq); } - ~PayloadAsyncRequest() { + ~PayloadAsyncRequest() override { payload_.Release(); // We do not own the payload_ } diff --git a/include/grpcpp/impl/codegen/service_type.h b/include/grpcpp/impl/codegen/service_type.h index 30be904a3c3..57ca9f09447 100644 --- a/include/grpcpp/impl/codegen/service_type.h +++ b/include/grpcpp/impl/codegen/service_type.h @@ -91,7 +91,7 @@ class Service { bool has_generic_methods() const { for (const auto& method : methods_) { - if (method.get() == nullptr) { + if (method == nullptr) { return true; } } diff --git a/include/grpcpp/resource_quota.h b/include/grpcpp/resource_quota.h index e51121329be..374feae732c 100644 --- a/include/grpcpp/resource_quota.h +++ b/include/grpcpp/resource_quota.h @@ -36,7 +36,7 @@ class ResourceQuota final : private ::grpc::GrpcLibraryCodegen { /// \param name - a unique name for this ResourceQuota. explicit ResourceQuota(const std::string& name); ResourceQuota(); - ~ResourceQuota(); + ~ResourceQuota() override; /// Resize this \a ResourceQuota to a new size. If \a new_size is smaller /// than the current size of the pool, memory usage will be monotonically diff --git a/include/grpcpp/security/credentials.h b/include/grpcpp/security/credentials.h index 2c915c8dc7c..2eae890fc70 100644 --- a/include/grpcpp/security/credentials.h +++ b/include/grpcpp/security/credentials.h @@ -69,7 +69,7 @@ std::shared_ptr XdsCredentials( class ChannelCredentials : private grpc::GrpcLibraryCodegen { public: ChannelCredentials(); - ~ChannelCredentials(); + ~ChannelCredentials() override; protected: friend std::shared_ptr CompositeChannelCredentials( @@ -126,7 +126,7 @@ class ChannelCredentials : private grpc::GrpcLibraryCodegen { class CallCredentials : private grpc::GrpcLibraryCodegen { public: CallCredentials(); - ~CallCredentials(); + ~CallCredentials() override; /// Apply this instance's credentials to \a call. virtual bool ApplyToCall(grpc_call* call) = 0; diff --git a/include/grpcpp/server.h b/include/grpcpp/server.h index 378e2b23673..65488e8656d 100644 --- a/include/grpcpp/server.h +++ b/include/grpcpp/server.h @@ -58,7 +58,7 @@ class ExternalConnectionAcceptorImpl; /// \a Server instances. class Server : public ServerInterface, private GrpcLibraryCodegen { public: - ~Server(); + ~Server() override; /// Block until the server shuts down. /// diff --git a/include/grpcpp/support/channel_arguments.h b/include/grpcpp/support/channel_arguments.h index 13146ca3b05..41a8ad387c5 100644 --- a/include/grpcpp/support/channel_arguments.h +++ b/include/grpcpp/support/channel_arguments.h @@ -117,7 +117,7 @@ class ChannelArguments { grpc_channel_args c_channel_args() const { grpc_channel_args out; out.num_args = args_.size(); - out.args = args_.empty() ? NULL : const_cast(&args_[0]); + out.args = args_.empty() ? nullptr : const_cast(&args_[0]); return out; }