From 789e8b33c857cb23fabb5b3b0659535790ea2500 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Tue, 30 Nov 2021 13:09:33 -0800 Subject: [PATCH] RefCountedPtr: Explicit constructor (#28157) * RefCountedPtr: Explicit constructor * Explicit constructor for WeakRefCountedPtr --- src/core/ext/filters/client_channel/dynamic_filters.cc | 2 +- src/core/ext/xds/xds_bootstrap.cc | 9 ++++++--- src/core/lib/gprpp/ref_counted_ptr.h | 6 ++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/core/ext/filters/client_channel/dynamic_filters.cc b/src/core/ext/filters/client_channel/dynamic_filters.cc index aac97725726..2956002d166 100644 --- a/src/core/ext/filters/client_channel/dynamic_filters.cc +++ b/src/core/ext/filters/client_channel/dynamic_filters.cc @@ -184,7 +184,7 @@ RefCountedPtr DynamicFilters::CreateCall( channel_stack_->call_stack_size; Call* call = static_cast(args.arena->Alloc(allocation_size)); new (call) Call(std::move(args), error); - return call; + return RefCountedPtr(call); } } // namespace grpc_core diff --git a/src/core/ext/xds/xds_bootstrap.cc b/src/core/ext/xds/xds_bootstrap.cc index 1a7a82cd270..d7655f8d38f 100644 --- a/src/core/ext/xds/xds_bootstrap.cc +++ b/src/core/ext/xds/xds_bootstrap.cc @@ -59,11 +59,14 @@ RefCountedPtr XdsChannelCredsRegistry::MakeChannelCreds(const std::string& creds_type, const Json& /*config*/) { if (creds_type == "google_default") { - return grpc_google_default_credentials_create(nullptr); + return RefCountedPtr( + grpc_google_default_credentials_create(nullptr)); } else if (creds_type == "insecure") { - return grpc_insecure_credentials_create(); + return RefCountedPtr( + grpc_insecure_credentials_create()); } else if (creds_type == "fake") { - return grpc_fake_transport_security_credentials_create(); + return RefCountedPtr( + grpc_fake_transport_security_credentials_create()); } return nullptr; } diff --git a/src/core/lib/gprpp/ref_counted_ptr.h b/src/core/lib/gprpp/ref_counted_ptr.h index 4ee1b950818..047ae95aec4 100644 --- a/src/core/lib/gprpp/ref_counted_ptr.h +++ b/src/core/lib/gprpp/ref_counted_ptr.h @@ -40,8 +40,7 @@ class RefCountedPtr { // If value is non-null, we take ownership of a ref to it. template - // NOLINTNEXTLINE(google-explicit-constructor) - RefCountedPtr(Y* value) : value_(value) {} + explicit RefCountedPtr(Y* value) : value_(value) {} // Move ctors. RefCountedPtr(RefCountedPtr&& other) noexcept { @@ -191,8 +190,7 @@ class WeakRefCountedPtr { // If value is non-null, we take ownership of a ref to it. template - // NOLINTNEXTLINE(google-explicit-constructor) - WeakRefCountedPtr(Y* value) { + explicit WeakRefCountedPtr(Y* value) { value_ = value; }