From 26ba5ae81a9b9ee446e9b6aed585b7b1dec1ea2d Mon Sep 17 00:00:00 2001 From: Derek Argueta Date: Sun, 28 Jul 2019 20:47:21 -0700 Subject: [PATCH] clang-tidy: modernize-use-default-member-init (#7745) Signed-off-by: Derek Argueta --- .clang-tidy | 1 + .../filesystem/posix/directory_iterator_impl.h | 5 ++--- source/common/grpc/google_async_client_impl.h | 4 ++-- source/common/signal/signal_action.h | 2 +- source/common/stats/stats_matcher_impl.h | 4 ++-- source/common/stats/symbol_table_impl.h | 4 ++-- .../filters/network/kafka/serialization.h | 2 +- source/extensions/tracers/zipkin/span_context.h | 12 ++++++------ .../tracers/zipkin/zipkin_core_types.h | 4 ++-- test/common/common/lock_guard_test.cc | 6 +++--- test/common/event/dispatcher_impl_test.cc | 6 ++---- test/common/upstream/eds_test.cc | 4 ++-- test/exe/main_common_test.cc | 16 ++++++---------- .../quiche/envoy_quic_alarm_test.cc | 4 ++-- .../quiche/platform/quic_mock_log_impl.h | 4 ++-- test/integration/sds_dynamic_integration_test.cc | 4 ++-- test/tools/router_check/router.h | 4 ++-- 17 files changed, 40 insertions(+), 46 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index b315a91c40d1..c62c2829fab3 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -23,6 +23,7 @@ WarningsAsErrors: 'abseil-duration-*, modernize-make-shared, modernize-make-unique, modernize-return-braced-init-list, + modernize-use-default-member-init, modernize-use-equals-default, modernize-use-override, modernize-use-using, diff --git a/source/common/filesystem/posix/directory_iterator_impl.h b/source/common/filesystem/posix/directory_iterator_impl.h index 889ffef1b5ac..ed5460dba673 100644 --- a/source/common/filesystem/posix/directory_iterator_impl.h +++ b/source/common/filesystem/posix/directory_iterator_impl.h @@ -12,8 +12,7 @@ namespace Filesystem { class DirectoryIteratorImpl : public DirectoryIterator { public: DirectoryIteratorImpl(const std::string& directory_path); - DirectoryIteratorImpl() - : directory_path_(""), dir_(nullptr), os_sys_calls_(Api::OsSysCallsSingleton::get()) {} + DirectoryIteratorImpl() : directory_path_(""), os_sys_calls_(Api::OsSysCallsSingleton::get()) {} ~DirectoryIteratorImpl() override; @@ -32,7 +31,7 @@ class DirectoryIteratorImpl : public DirectoryIterator { FileType fileType(const std::string& name) const; std::string directory_path_; - DIR* dir_; + DIR* dir_{nullptr}; Api::OsSysCallsImpl& os_sys_calls_; }; diff --git a/source/common/grpc/google_async_client_impl.h b/source/common/grpc/google_async_client_impl.h index f2e9eb651b7e..da834f1b82a9 100644 --- a/source/common/grpc/google_async_client_impl.h +++ b/source/common/grpc/google_async_client_impl.h @@ -237,10 +237,10 @@ class GoogleAsyncStreamImpl : public RawAsyncStream, struct PendingMessage { PendingMessage(Buffer::InstancePtr request, bool end_stream); // End-of-stream with no additional message. - PendingMessage() : end_stream_(true) {} + PendingMessage() = default; const absl::optional buf_; - const bool end_stream_; + const bool end_stream_{true}; }; GoogleAsyncTag init_tag_{*this, GoogleAsyncTag::Operation::Init}; diff --git a/source/common/signal/signal_action.h b/source/common/signal/signal_action.h index b7ae17cd426b..afe0690d00fd 100644 --- a/source/common/signal/signal_action.h +++ b/source/common/signal/signal_action.h @@ -53,7 +53,7 @@ class SignalAction : NonCopyable { public: SignalAction() : guard_size_(sysconf(_SC_PAGE_SIZE)), - altstack_size_(std::max(guard_size_ * 4, static_cast(MINSIGSTKSZ))), altstack_() { + altstack_size_(std::max(guard_size_ * 4, static_cast(MINSIGSTKSZ))) { mapAndProtectStackMemory(); installSigHandlers(); } diff --git a/source/common/stats/stats_matcher_impl.h b/source/common/stats/stats_matcher_impl.h index 10658fd87e57..3712a466d3f6 100644 --- a/source/common/stats/stats_matcher_impl.h +++ b/source/common/stats/stats_matcher_impl.h @@ -21,7 +21,7 @@ class StatsMatcherImpl : public StatsMatcher { explicit StatsMatcherImpl(const envoy::config::metrics::v2::StatsConfig& config); // Default constructor simply allows everything. - StatsMatcherImpl() : is_inclusive_(true) {} + StatsMatcherImpl() = default; // StatsMatcher bool rejects(const std::string& name) const override; @@ -31,7 +31,7 @@ class StatsMatcherImpl : public StatsMatcher { private: // Bool indicating whether or not the StatsMatcher is including or excluding stats by default. See // StatsMatcherImpl::rejects() for much more detail. - bool is_inclusive_; + bool is_inclusive_{true}; std::vector matchers_; }; diff --git a/source/common/stats/symbol_table_impl.h b/source/common/stats/symbol_table_impl.h index 259e011f6b41..8860980017e2 100644 --- a/source/common/stats/symbol_table_impl.h +++ b/source/common/stats/symbol_table_impl.h @@ -310,7 +310,7 @@ class StatName { explicit StatName(const SymbolTable::Storage size_and_data) : size_and_data_(size_and_data) {} // Constructs an empty StatName object. - StatName() : size_and_data_(nullptr) {} + StatName() = default; // Constructs a StatName object with new storage, which must be of size // src.size(). This is used in the a flow where we first construct a StatName @@ -365,7 +365,7 @@ class StatName { bool empty() const { return size_and_data_ == nullptr || dataSize() == 0; } private: - const uint8_t* size_and_data_; + const uint8_t* size_and_data_{nullptr}; }; StatName StatNameStorage::statName() const { return StatName(bytes_.get()); } diff --git a/source/extensions/filters/network/kafka/serialization.h b/source/extensions/filters/network/kafka/serialization.h index ea0ce7ca9029..3e7fdc8e2ec6 100644 --- a/source/extensions/filters/network/kafka/serialization.h +++ b/source/extensions/filters/network/kafka/serialization.h @@ -60,7 +60,7 @@ template class Deserializer { */ template class IntDeserializer : public Deserializer { public: - IntDeserializer() : written_{0}, ready_(false){}; + IntDeserializer() : written_{0} {}; uint32_t feed(absl::string_view& data) override { const uint32_t available = std::min(sizeof(buf_) - written_, data.size()); diff --git a/source/extensions/tracers/zipkin/span_context.h b/source/extensions/tracers/zipkin/span_context.h index 78eaa5b5d1c3..6dd08c3b291b 100644 --- a/source/extensions/tracers/zipkin/span_context.h +++ b/source/extensions/tracers/zipkin/span_context.h @@ -20,7 +20,7 @@ class SpanContext { /** * Default constructor. Creates an empty context. */ - SpanContext() : trace_id_high_(0), trace_id_(0), id_(0), parent_id_(0), sampled_(false) {} + SpanContext() = default; /** * Constructor that creates a context object from the supplied trace, span and @@ -75,11 +75,11 @@ class SpanContext { bool sampled() const { return sampled_; } private: - const uint64_t trace_id_high_; - const uint64_t trace_id_; - const uint64_t id_; - const uint64_t parent_id_; - const bool sampled_; + const uint64_t trace_id_high_{0}; + const uint64_t trace_id_{0}; + const uint64_t id_{0}; + const uint64_t parent_id_{0}; + const bool sampled_{false}; }; } // namespace Zipkin diff --git a/source/extensions/tracers/zipkin/zipkin_core_types.h b/source/extensions/tracers/zipkin/zipkin_core_types.h index d9b5f10fc2d8..8c9ff909241f 100644 --- a/source/extensions/tracers/zipkin/zipkin_core_types.h +++ b/source/extensions/tracers/zipkin/zipkin_core_types.h @@ -118,7 +118,7 @@ class Annotation : public ZipkinBase { /** * Default constructor. Creates an empty annotation. */ - Annotation() : timestamp_(0) {} + Annotation() = default; /** * Constructor that creates an annotation based on the given parameters. @@ -187,7 +187,7 @@ class Annotation : public ZipkinBase { const std::string toJson() override; private: - uint64_t timestamp_; + uint64_t timestamp_{0}; std::string value_; absl::optional endpoint_; }; diff --git a/test/common/common/lock_guard_test.cc b/test/common/common/lock_guard_test.cc index 55f505f9ab58..163b535378b2 100644 --- a/test/common/common/lock_guard_test.cc +++ b/test/common/common/lock_guard_test.cc @@ -8,10 +8,10 @@ namespace Thread { class ThreadTest : public testing::Test { protected: - ThreadTest() : a_(0), b_(0) {} - int a_ GUARDED_BY(a_mutex_); + ThreadTest() = default; + int a_ GUARDED_BY(a_mutex_){0}; MutexBasicLockable a_mutex_; - int b_; + int b_{0}; }; TEST_F(ThreadTest, TestLockGuard) { diff --git a/test/common/event/dispatcher_impl_test.cc b/test/common/event/dispatcher_impl_test.cc index c2b7a4407b7e..c0605a70c3ca 100644 --- a/test/common/event/dispatcher_impl_test.cc +++ b/test/common/event/dispatcher_impl_test.cc @@ -67,9 +67,7 @@ TEST(DeferredDeleteTest, DeferredDelete) { class DispatcherImplTest : public testing::Test { protected: - DispatcherImplTest() - : api_(Api::createApiForTest()), dispatcher_(api_->allocateDispatcher()), - work_finished_(false) { + DispatcherImplTest() : api_(Api::createApiForTest()), dispatcher_(api_->allocateDispatcher()) { dispatcher_thread_ = api_->threadFactory().createThread([this]() { // Must create a keepalive timer to keep the dispatcher from exiting. std::chrono::milliseconds time_interval(500); @@ -93,7 +91,7 @@ class DispatcherImplTest : public testing::Test { Thread::MutexBasicLockable mu_; Thread::CondVar cv_; - bool work_finished_; + bool work_finished_{false}; TimerPtr keepalive_timer_; }; diff --git a/test/common/upstream/eds_test.cc b/test/common/upstream/eds_test.cc index 83f8d3f27c2f..a3909a8ca79c 100644 --- a/test/common/upstream/eds_test.cc +++ b/test/common/upstream/eds_test.cc @@ -1658,7 +1658,7 @@ TEST_F(EdsTest, MalformedIP) { class EdsAssignmentTimeoutTest : public EdsTest { public: - EdsAssignmentTimeoutTest() : interval_timer_(nullptr) { + EdsAssignmentTimeoutTest() { EXPECT_CALL(dispatcher_, createTimer_(_)) .WillOnce(Invoke([this](Event::TimerCb cb) { timer_cb_ = cb; @@ -1671,7 +1671,7 @@ class EdsAssignmentTimeoutTest : public EdsTest { resetCluster(); } - Event::MockTimer* interval_timer_; + Event::MockTimer* interval_timer_{nullptr}; Event::TimerCb timer_cb_; }; diff --git a/test/exe/main_common_test.cc b/test/exe/main_common_test.cc index 1d412d13a6e1..4dadcb31875f 100644 --- a/test/exe/main_common_test.cc +++ b/test/exe/main_common_test.cc @@ -147,11 +147,7 @@ INSTANTIATE_TEST_SUITE_P(IpVersions, MainCommonTest, class AdminRequestTest : public MainCommonTest { protected: - AdminRequestTest() - : envoy_return_(false), envoy_started_(false), envoy_finished_(false), - pause_before_run_(false), pause_after_run_(false) { - addArg("--disable-hot-restart"); - } + AdminRequestTest() { addArg("--disable-hot-restart"); } // Runs an admin request specified in path, blocking until completion, and // returning the response body. @@ -234,11 +230,11 @@ class AdminRequestTest : public MainCommonTest { absl::Notification finished_; absl::Notification resume_; absl::Notification pause_point_; - bool envoy_return_; - bool envoy_started_; - bool envoy_finished_; - bool pause_before_run_; - bool pause_after_run_; + bool envoy_return_{false}; + bool envoy_started_{false}; + bool envoy_finished_{false}; + bool pause_before_run_{false}; + bool pause_after_run_{false}; }; TEST_P(AdminRequestTest, AdminRequestGetStatsAndQuit) { diff --git a/test/extensions/quic_listeners/quiche/envoy_quic_alarm_test.cc b/test/extensions/quic_listeners/quiche/envoy_quic_alarm_test.cc index d2597b2e996b..9ab3753ec855 100644 --- a/test/extensions/quic_listeners/quiche/envoy_quic_alarm_test.cc +++ b/test/extensions/quic_listeners/quiche/envoy_quic_alarm_test.cc @@ -16,7 +16,7 @@ namespace Quic { class TestDelegate : public quic::QuicAlarm::Delegate { public: - TestDelegate() : fired_(false) {} + TestDelegate() = default; // quic::QuicAlarm::Delegate void OnAlarm() override { fired_ = true; } @@ -25,7 +25,7 @@ class TestDelegate : public quic::QuicAlarm::Delegate { void set_fired(bool fired) { fired_ = fired; } private: - bool fired_; + bool fired_{false}; }; class EnvoyQuicAlarmTest : public ::testing::Test { diff --git a/test/extensions/quic_listeners/quiche/platform/quic_mock_log_impl.h b/test/extensions/quic_listeners/quiche/platform/quic_mock_log_impl.h index ea9326cc4eb2..f5cdc5e74499 100644 --- a/test/extensions/quic_listeners/quiche/platform/quic_mock_log_impl.h +++ b/test/extensions/quic_listeners/quiche/platform/quic_mock_log_impl.h @@ -19,7 +19,7 @@ namespace quic { // destruction(or StopCapturingLogs()). class QuicEnvoyMockLog : public QuicLogSink { public: - QuicEnvoyMockLog() : is_capturing_(false) {} + QuicEnvoyMockLog() = default; ~QuicEnvoyMockLog() override { if (is_capturing_) { @@ -43,7 +43,7 @@ class QuicEnvoyMockLog : public QuicLogSink { private: QuicLogSink* original_sink_; - bool is_capturing_; + bool is_capturing_{false}; }; // ScopedDisableExitOnDFatal is used to disable exiting the program when we encounter a diff --git a/test/integration/sds_dynamic_integration_test.cc b/test/integration/sds_dynamic_integration_test.cc index f91c7a5c383a..d260bdf6f0d0 100644 --- a/test/integration/sds_dynamic_integration_test.cc +++ b/test/integration/sds_dynamic_integration_test.cc @@ -239,7 +239,7 @@ TEST_P(SdsDynamicDownstreamIntegrationTest, WrongSecretFirst) { class SdsDynamicDownstreamCertValidationContextTest : public SdsDynamicDownstreamIntegrationTest { public: - SdsDynamicDownstreamCertValidationContextTest() : use_combined_validation_context_(false) {} + SdsDynamicDownstreamCertValidationContextTest() = default; void initialize() override { config_helper_.addConfigModifier([this](envoy::config::bootstrap::v2::Bootstrap& bootstrap) { @@ -285,7 +285,7 @@ class SdsDynamicDownstreamCertValidationContextTest : public SdsDynamicDownstrea void enableCombinedValidationContext(bool enable) { use_combined_validation_context_ = enable; } private: - bool use_combined_validation_context_; + bool use_combined_validation_context_{false}; }; INSTANTIATE_TEST_SUITE_P(IpVersionsClientType, SdsDynamicDownstreamCertValidationContextTest, diff --git a/test/tools/router_check/router.h b/test/tools/router_check/router.h index 026bc1343a9a..6c507f5bc8bd 100644 --- a/test/tools/router_check/router.h +++ b/test/tools/router_check/router.h @@ -29,7 +29,7 @@ namespace Envoy { * input file. */ struct ToolConfig { - ToolConfig() : random_value_(0){}; + ToolConfig() = default; /** * @param check_config tool config json object pointer. @@ -49,7 +49,7 @@ struct ToolConfig { std::unique_ptr headers_; Router::RouteConstSharedPtr route_; - int random_value_; + int random_value_{0}; private: ToolConfig(std::unique_ptr headers, int random_value);