From 20509e823d20fa7dac3da3d843bcda39c4897131 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Thu, 3 Dec 2020 19:22:22 -0800 Subject: [PATCH] Fix google-explicit-constructor --- include/grpcpp/impl/codegen/byte_buffer.h | 4 ++++ include/grpcpp/impl/codegen/call_op_set.h | 2 +- include/grpcpp/impl/codegen/callback_common.h | 1 + include/grpcpp/impl/codegen/completion_queue.h | 4 ++-- include/grpcpp/impl/codegen/delegating_channel.h | 3 ++- include/grpcpp/impl/codegen/grpc_library.h | 3 ++- include/grpcpp/impl/codegen/method_handler.h | 2 +- include/grpcpp/impl/codegen/slice.h | 3 ++- include/grpcpp/impl/codegen/string_ref.h | 2 ++ include/grpcpp/impl/codegen/time.h | 2 ++ include/grpcpp/impl/server_initializer.h | 2 +- include/grpcpp/security/server_credentials.h | 2 +- include/grpcpp/security/tls_certificate_provider.h | 4 ++-- include/grpcpp/security/tls_credentials_options.h | 5 +++-- 14 files changed, 26 insertions(+), 13 deletions(-) diff --git a/include/grpcpp/impl/codegen/byte_buffer.h b/include/grpcpp/impl/codegen/byte_buffer.h index a8836fd6888..4347745c2d7 100644 --- a/include/grpcpp/impl/codegen/byte_buffer.h +++ b/include/grpcpp/impl/codegen/byte_buffer.h @@ -196,10 +196,14 @@ class ByteBuffer final { class ByteBufferPointer { public: + /* NOLINTNEXTLINE(google-explicit-constructor) */ ByteBufferPointer(const ByteBuffer* b) : bbuf_(const_cast(b)) {} + /* NOLINTNEXTLINE(google-explicit-constructor) */ operator ByteBuffer*() { return bbuf_; } + /* NOLINTNEXTLINE(google-explicit-constructor) */ operator grpc_byte_buffer*() { return bbuf_->buffer_; } + /* NOLINTNEXTLINE(google-explicit-constructor) */ operator grpc_byte_buffer**() { return &bbuf_->buffer_; } private: diff --git a/include/grpcpp/impl/codegen/call_op_set.h b/include/grpcpp/impl/codegen/call_op_set.h index dbc8b9b65dc..370d51967d0 100644 --- a/include/grpcpp/impl/codegen/call_op_set.h +++ b/include/grpcpp/impl/codegen/call_op_set.h @@ -512,7 +512,7 @@ class DeserializeFunc { template class DeserializeFuncType final : public DeserializeFunc { public: - DeserializeFuncType(R* message) : message_(message) {} + explicit DeserializeFuncType(R* message) : message_(message) {} Status Deserialize(ByteBuffer* buf) override { return SerializationTraits::Deserialize(buf->bbuf_ptr(), message_); } diff --git a/include/grpcpp/impl/codegen/callback_common.h b/include/grpcpp/impl/codegen/callback_common.h index 040c5d5c981..086a179a808 100644 --- a/include/grpcpp/impl/codegen/callback_common.h +++ b/include/grpcpp/impl/codegen/callback_common.h @@ -190,6 +190,7 @@ class CallbackWithSuccessTag void force_run(bool ok) { Run(ok); } /// check if this tag is currently set + /* NOLINTNEXTLINE(google-explicit-constructor) */ operator bool() const { return call_ != nullptr; } private: diff --git a/include/grpcpp/impl/codegen/completion_queue.h b/include/grpcpp/impl/codegen/completion_queue.h index 554f4b18db5..f6589f06c26 100644 --- a/include/grpcpp/impl/codegen/completion_queue.h +++ b/include/grpcpp/impl/codegen/completion_queue.h @@ -243,7 +243,7 @@ class CompletionQueue : private ::grpc::GrpcLibraryCodegen { protected: /// Private constructor of CompletionQueue only visible to friend classes - CompletionQueue(const grpc_completion_queue_attributes& attributes) { + explicit CompletionQueue(const grpc_completion_queue_attributes& attributes) { cq_ = ::grpc::g_core_codegen_interface->grpc_completion_queue_create( ::grpc::g_core_codegen_interface->grpc_completion_queue_factory_lookup( &attributes), @@ -301,7 +301,7 @@ class CompletionQueue : private ::grpc::GrpcLibraryCodegen { /// initialized, it must be flushed on the same thread. class CompletionQueueTLSCache { public: - CompletionQueueTLSCache(CompletionQueue* cq); + explicit CompletionQueueTLSCache(CompletionQueue* cq); ~CompletionQueueTLSCache(); bool Flush(void** tag, bool* ok); diff --git a/include/grpcpp/impl/codegen/delegating_channel.h b/include/grpcpp/impl/codegen/delegating_channel.h index 85d46d9f96e..0479567b864 100644 --- a/include/grpcpp/impl/codegen/delegating_channel.h +++ b/include/grpcpp/impl/codegen/delegating_channel.h @@ -30,7 +30,8 @@ class DelegatingChannel : public ::grpc::ChannelInterface { public: ~DelegatingChannel() override {} - DelegatingChannel(std::shared_ptr<::grpc::ChannelInterface> delegate_channel) + explicit DelegatingChannel( + std::shared_ptr<::grpc::ChannelInterface> delegate_channel) : delegate_channel_(delegate_channel) {} grpc_connectivity_state GetState(bool try_to_connect) override { diff --git a/include/grpcpp/impl/codegen/grpc_library.h b/include/grpcpp/impl/codegen/grpc_library.h index 17c904d71a1..660d6d0abdc 100644 --- a/include/grpcpp/impl/codegen/grpc_library.h +++ b/include/grpcpp/impl/codegen/grpc_library.h @@ -37,7 +37,8 @@ extern GrpcLibraryInterface* g_glip; /// Classes that require gRPC to be initialized should inherit from this class. class GrpcLibraryCodegen { public: - GrpcLibraryCodegen(bool call_grpc_init = true) : grpc_init_called_(false) { + explicit GrpcLibraryCodegen(bool call_grpc_init = true) + : grpc_init_called_(false) { if (call_grpc_init) { GPR_CODEGEN_ASSERT(g_glip && "gRPC library not initialized. See " diff --git a/include/grpcpp/impl/codegen/method_handler.h b/include/grpcpp/impl/codegen/method_handler.h index 604de8905d0..963423df467 100644 --- a/include/grpcpp/impl/codegen/method_handler.h +++ b/include/grpcpp/impl/codegen/method_handler.h @@ -261,7 +261,7 @@ class ServerStreamingHandler : public ::grpc::internal::MethodHandler { template class TemplatedBidiStreamingHandler : public ::grpc::internal::MethodHandler { public: - TemplatedBidiStreamingHandler( + explicit TemplatedBidiStreamingHandler( std::function<::grpc::Status(::grpc::ServerContext*, Streamer*)> func) : func_(func), write_needed_(WriteNeeded) {} diff --git a/include/grpcpp/impl/codegen/slice.h b/include/grpcpp/impl/codegen/slice.h index 1ef093ec00a..ea550259e80 100644 --- a/include/grpcpp/impl/codegen/slice.h +++ b/include/grpcpp/impl/codegen/slice.h @@ -49,7 +49,7 @@ class Slice final { Slice(grpc_slice slice, StealRef) : slice_(slice) {} /// Allocate a slice of specified size - Slice(size_t len) + explicit Slice(size_t len) : slice_(g_core_codegen_interface->grpc_slice_malloc(len)) {} /// Construct a slice from a copied buffer @@ -58,6 +58,7 @@ class Slice final { reinterpret_cast(buf), len)) {} /// Construct a slice from a copied string + /* NOLINTNEXTLINE(google-explicit-constructor) */ Slice(const std::string& str) : slice_(g_core_codegen_interface->grpc_slice_from_copied_buffer( str.c_str(), str.length())) {} diff --git a/include/grpcpp/impl/codegen/string_ref.h b/include/grpcpp/impl/codegen/string_ref.h index 6bdcfc1a6a6..153f37102d8 100644 --- a/include/grpcpp/impl/codegen/string_ref.h +++ b/include/grpcpp/impl/codegen/string_ref.h @@ -57,8 +57,10 @@ class string_ref { return *this; } + /* NOLINTNEXTLINE(google-explicit-constructor) */ string_ref(const char* s) : data_(s), length_(strlen(s)) {} string_ref(const char* s, size_t l) : data_(s), length_(l) {} + /* NOLINTNEXTLINE(google-explicit-constructor) */ string_ref(const std::string& s) : data_(s.data()), length_(s.length()) {} /// iterators diff --git a/include/grpcpp/impl/codegen/time.h b/include/grpcpp/impl/codegen/time.h index a08e9cbe189..340a06f5002 100644 --- a/include/grpcpp/impl/codegen/time.h +++ b/include/grpcpp/impl/codegen/time.h @@ -50,6 +50,7 @@ class TimePoint { template <> class TimePoint { public: + /* NOLINTNEXTLINE(google-explicit-constructor) */ TimePoint(const gpr_timespec& time) : time_(time) {} gpr_timespec raw_time() { return time_; } @@ -73,6 +74,7 @@ std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t); template <> class TimePoint { public: + /* NOLINTNEXTLINE(google-explicit-constructor) */ TimePoint(const std::chrono::system_clock::time_point& time) { Timepoint2Timespec(time, &time_); } diff --git a/include/grpcpp/impl/server_initializer.h b/include/grpcpp/impl/server_initializer.h index b4e6b45b7c6..610df802930 100644 --- a/include/grpcpp/impl/server_initializer.h +++ b/include/grpcpp/impl/server_initializer.h @@ -30,7 +30,7 @@ class Service; class ServerInitializer { public: - ServerInitializer(grpc::Server* server) : server_(server) {} + explicit ServerInitializer(grpc::Server* server) : server_(server) {} bool RegisterService(std::shared_ptr service) { if (!server_->RegisterService(nullptr, service.get())) { diff --git a/include/grpcpp/security/server_credentials.h b/include/grpcpp/security/server_credentials.h index d2a9ef1e343..ad7c0e78cac 100644 --- a/include/grpcpp/security/server_credentials.h +++ b/include/grpcpp/security/server_credentials.h @@ -40,7 +40,7 @@ struct SslServerCredentialsOptions { SslServerCredentialsOptions() : force_client_auth(false), client_certificate_request(GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE) {} - SslServerCredentialsOptions( + explicit SslServerCredentialsOptions( grpc_ssl_client_certificate_request_type request_type) : force_client_auth(false), client_certificate_request(request_type) {} diff --git a/include/grpcpp/security/tls_certificate_provider.h b/include/grpcpp/security/tls_certificate_provider.h index ec006f353b1..a7480cc6191 100644 --- a/include/grpcpp/security/tls_certificate_provider.h +++ b/include/grpcpp/security/tls_certificate_provider.h @@ -59,10 +59,10 @@ class StaticDataCertificateProvider : public CertificateProviderInterface { const std::string& root_certificate, const std::vector& identity_key_cert_pairs); - StaticDataCertificateProvider(const std::string& root_certificate) + explicit StaticDataCertificateProvider(const std::string& root_certificate) : StaticDataCertificateProvider(root_certificate, {}) {} - StaticDataCertificateProvider( + explicit StaticDataCertificateProvider( const std::vector& identity_key_cert_pairs) : StaticDataCertificateProvider("", identity_key_cert_pairs) {} diff --git a/include/grpcpp/security/tls_credentials_options.h b/include/grpcpp/security/tls_credentials_options.h index aaa1a90ca43..6abdcaa7efe 100644 --- a/include/grpcpp/security/tls_credentials_options.h +++ b/include/grpcpp/security/tls_credentials_options.h @@ -54,7 +54,8 @@ class TlsServerAuthorizationCheckArg { /** TlsServerAuthorizationCheckArg does not take ownership of the C arg passed * to the constructor. One must remember to free any memory allocated to the * C arg after using the setter functions below. **/ - TlsServerAuthorizationCheckArg(grpc_tls_server_authorization_check_arg* arg); + explicit TlsServerAuthorizationCheckArg( + grpc_tls_server_authorization_check_arg* arg); ~TlsServerAuthorizationCheckArg(); /** Getters for member fields. **/ @@ -101,7 +102,7 @@ struct TlsServerAuthorizationCheckInterface { * purposes for now and it is subject to change. **/ class TlsServerAuthorizationCheckConfig { public: - TlsServerAuthorizationCheckConfig( + explicit TlsServerAuthorizationCheckConfig( std::shared_ptr server_authorization_check_interface); ~TlsServerAuthorizationCheckConfig();