diff --git a/.github/workflows/clang-tidy.yaml b/.github/workflows/clang-tidy.yaml index ed9bcff238..3e1b6c3afc 100644 --- a/.github/workflows/clang-tidy.yaml +++ b/.github/workflows/clang-tidy.yaml @@ -17,9 +17,9 @@ jobs: matrix: include: - cmake_options: all-options-abiv1-preview - warning_limit: 109 + warning_limit: 86 - cmake_options: all-options-abiv2-preview - warning_limit: 109 + warning_limit: 86 steps: - name: Harden the runner (Audit all outbound calls) uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1 diff --git a/CHANGELOG.md b/CHANGELOG.md index e29ce90b23..dcff620345 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,9 @@ Increment the: * [CodeHealth] Fix clang-tidy warnings part 2 [#3496](https://github.com/open-telemetry/opentelemetry-cpp/pull/3496) +* [CodeHealth] Fix clang-tidy warnings part 3 + [#3496](https://github.com/open-telemetry/opentelemetry-cpp/pull/3498) + Important changes: * [REMOVAL] Removed deprecated semantic convention header files diff --git a/api/test/context/propagation/composite_propagator_test.cc b/api/test/context/propagation/composite_propagator_test.cc index 87c0e6cb63..49b1668cb5 100644 --- a/api/test/context/propagation/composite_propagator_test.cc +++ b/api/test/context/propagation/composite_propagator_test.cc @@ -73,13 +73,11 @@ class CompositePropagatorTest : public ::testing::Test propogator_list.push_back(std::move(b3_propogator)); composite_propagator_ = - new context::propagation::CompositePropagator(std::move(propogator_list)); + std::make_shared(std::move(propogator_list)); } - ~CompositePropagatorTest() override { delete composite_propagator_; } - protected: - context::propagation::CompositePropagator *composite_propagator_; + std::shared_ptr composite_propagator_; }; TEST_F(CompositePropagatorTest, Extract) diff --git a/api/test/nostd/shared_ptr_test.cc b/api/test/nostd/shared_ptr_test.cc index cd82398fb5..fa3d97c493 100644 --- a/api/test/nostd/shared_ptr_test.cc +++ b/api/test/nostd/shared_ptr_test.cc @@ -19,6 +19,11 @@ class A ~A() { destructed_ = true; } + A(const A &) = delete; + A(A &&) = delete; + A &operator=(const A &) = delete; + A &operator=(A &&) = delete; + private: bool &destructed_; }; @@ -33,13 +38,16 @@ class C { public: virtual ~C() {} + C() = default; + + C(const C &) = delete; + C(C &&) = delete; + C &operator=(const C &) = delete; + C &operator=(C &&) = delete; }; class D : public C -{ -public: - ~D() override {} -}; +{}; TEST(SharedPtrTest, DefaultConstruction) { diff --git a/api/test/nostd/unique_ptr_test.cc b/api/test/nostd/unique_ptr_test.cc index 5e448402b6..3660bc5d22 100644 --- a/api/test/nostd/unique_ptr_test.cc +++ b/api/test/nostd/unique_ptr_test.cc @@ -17,6 +17,11 @@ class A ~A() { destructed_ = true; } + A(const A &) = delete; + A(A &&) = delete; + A &operator=(const A &) = delete; + A &operator=(A &&) = delete; + private: bool &destructed_; }; diff --git a/api/test/nostd/variant_test.cc b/api/test/nostd/variant_test.cc index 11d9fe2974..193bd4874a 100644 --- a/api/test/nostd/variant_test.cc +++ b/api/test/nostd/variant_test.cc @@ -14,6 +14,11 @@ class DestroyCounter explicit DestroyCounter(int *count) : count_{count} {} ~DestroyCounter() { ++*count_; } + DestroyCounter(const DestroyCounter &) = default; + DestroyCounter &operator=(const DestroyCounter &) = default; + DestroyCounter(DestroyCounter &&) = default; + DestroyCounter &operator=(DestroyCounter &&) = default; + private: int *count_; }; diff --git a/examples/otlp/http_instrumented_main.cc b/examples/otlp/http_instrumented_main.cc index 3b126b4e62..745d65216f 100644 --- a/examples/otlp/http_instrumented_main.cc +++ b/examples/otlp/http_instrumented_main.cc @@ -89,7 +89,6 @@ class MyThreadInstrumentation : public opentelemetry::sdk::common::ThreadInstrum const std::string &priority) : thread_name_(thread_name), network_name_(network_name), priority_(priority) {} - ~MyThreadInstrumentation() override = default; void OnStart() override { diff --git a/examples/plugin/plugin/tracer.cc b/examples/plugin/plugin/tracer.cc index a89640e000..5a5c9128ea 100644 --- a/examples/plugin/plugin/tracer.cc +++ b/examples/plugin/plugin/tracer.cc @@ -35,6 +35,11 @@ class Span final : public trace::Span ~Span() override { std::cout << "~Span\n"; } + Span(const Span &) = delete; + Span &operator=(const Span &) = delete; + Span(Span &&) = delete; + Span &operator=(Span &&) = delete; + // opentelemetry::trace::Span void SetAttribute(nostd::string_view /*name*/, const common::AttributeValue & /*value*/) noexcept override diff --git a/exporters/elasticsearch/src/es_log_record_exporter.cc b/exporters/elasticsearch/src/es_log_record_exporter.cc index 3a0b0b6715..d617a1ac16 100644 --- a/exporters/elasticsearch/src/es_log_record_exporter.cc +++ b/exporters/elasticsearch/src/es_log_record_exporter.cc @@ -223,6 +223,11 @@ class AsyncResponseHandler : public http_client::EventHandler console_debug_{console_debug} {} + AsyncResponseHandler(const AsyncResponseHandler &) = delete; + AsyncResponseHandler &operator=(const AsyncResponseHandler &) = delete; + AsyncResponseHandler(AsyncResponseHandler &&) = delete; + AsyncResponseHandler &operator=(AsyncResponseHandler &&) = delete; + /** * Cleans up the session in the destructor. */ diff --git a/exporters/otlp/src/otlp_grpc_client.cc b/exporters/otlp/src/otlp_grpc_client.cc index cec55ba116..2bc66aa739 100644 --- a/exporters/otlp/src/otlp_grpc_client.cc +++ b/exporters/otlp/src/otlp_grpc_client.cc @@ -67,8 +67,12 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpGrpcAsyncCallDataBase opentelemetry::sdk::common::ExportResult::kFailure; GrpcAsyncCallback grpc_async_callback = nullptr; - OtlpGrpcAsyncCallDataBase() {} - virtual ~OtlpGrpcAsyncCallDataBase() {} + OtlpGrpcAsyncCallDataBase() = default; + virtual ~OtlpGrpcAsyncCallDataBase() = default; + OtlpGrpcAsyncCallDataBase(const OtlpGrpcAsyncCallDataBase &) = delete; + OtlpGrpcAsyncCallDataBase &operator=(const OtlpGrpcAsyncCallDataBase &) = delete; + OtlpGrpcAsyncCallDataBase(OtlpGrpcAsyncCallDataBase &&) = delete; + OtlpGrpcAsyncCallDataBase &operator=(OtlpGrpcAsyncCallDataBase &&) = delete; }; // When building with -fvisibility=default, we hide the symbols and vtable to ensure we always use @@ -90,8 +94,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpGrpcAsyncCallData : public OtlpGrpcAsyncCal ResponseType *)> result_callback; - OtlpGrpcAsyncCallData() {} - ~OtlpGrpcAsyncCallData() override {} + OtlpGrpcAsyncCallData() = default; }; } // namespace #endif diff --git a/exporters/otlp/test/otlp_file_client_test.cc b/exporters/otlp/test/otlp_file_client_test.cc index 826b695b52..aa7aec7eff 100644 --- a/exporters/otlp/test/otlp_file_client_test.cc +++ b/exporters/otlp/test/otlp_file_client_test.cc @@ -61,8 +61,12 @@ namespace resource = opentelemetry::sdk::resource; class ProtobufGlobalSymbolGuard { public: - ProtobufGlobalSymbolGuard() {} + ProtobufGlobalSymbolGuard() = default; ~ProtobufGlobalSymbolGuard() { google::protobuf::ShutdownProtobufLibrary(); } + ProtobufGlobalSymbolGuard(const ProtobufGlobalSymbolGuard &) = delete; + ProtobufGlobalSymbolGuard &operator=(const ProtobufGlobalSymbolGuard &) = delete; + ProtobufGlobalSymbolGuard(ProtobufGlobalSymbolGuard &&) = delete; + ProtobufGlobalSymbolGuard &operator=(ProtobufGlobalSymbolGuard &&) = delete; }; static std::tm GetLocalTime(std::chrono::system_clock::time_point tp) diff --git a/exporters/otlp/test/otlp_file_exporter_test.cc b/exporters/otlp/test/otlp_file_exporter_test.cc index cf3abc52e5..ea3fecb7bd 100644 --- a/exporters/otlp/test/otlp_file_exporter_test.cc +++ b/exporters/otlp/test/otlp_file_exporter_test.cc @@ -61,8 +61,12 @@ namespace resource = opentelemetry::sdk::resource; class ProtobufGlobalSymbolGuard { public: - ProtobufGlobalSymbolGuard() {} + ProtobufGlobalSymbolGuard() = default; ~ProtobufGlobalSymbolGuard() { google::protobuf::ShutdownProtobufLibrary(); } + ProtobufGlobalSymbolGuard(const ProtobufGlobalSymbolGuard &) = delete; + ProtobufGlobalSymbolGuard &operator=(const ProtobufGlobalSymbolGuard &) = delete; + ProtobufGlobalSymbolGuard(ProtobufGlobalSymbolGuard &&) = delete; + ProtobufGlobalSymbolGuard &operator=(ProtobufGlobalSymbolGuard &&) = delete; }; template diff --git a/exporters/otlp/test/otlp_file_log_record_exporter_test.cc b/exporters/otlp/test/otlp_file_log_record_exporter_test.cc index 67cc24d258..c2c081e857 100644 --- a/exporters/otlp/test/otlp_file_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_file_log_record_exporter_test.cc @@ -49,8 +49,12 @@ namespace otlp class ProtobufGlobalSymbolGuard { public: - ProtobufGlobalSymbolGuard() {} + ProtobufGlobalSymbolGuard() = default; ~ProtobufGlobalSymbolGuard() { google::protobuf::ShutdownProtobufLibrary(); } + ProtobufGlobalSymbolGuard(const ProtobufGlobalSymbolGuard &) = delete; + ProtobufGlobalSymbolGuard &operator=(const ProtobufGlobalSymbolGuard &) = delete; + ProtobufGlobalSymbolGuard(ProtobufGlobalSymbolGuard &&) = delete; + ProtobufGlobalSymbolGuard &operator=(ProtobufGlobalSymbolGuard &&) = delete; }; template diff --git a/exporters/otlp/test/otlp_file_metric_exporter_test.cc b/exporters/otlp/test/otlp_file_metric_exporter_test.cc index 7c8a388eae..965da942ae 100644 --- a/exporters/otlp/test/otlp_file_metric_exporter_test.cc +++ b/exporters/otlp/test/otlp_file_metric_exporter_test.cc @@ -47,8 +47,12 @@ namespace otlp class ProtobufGlobalSymbolGuard { public: - ProtobufGlobalSymbolGuard() {} + ProtobufGlobalSymbolGuard() = default; ~ProtobufGlobalSymbolGuard() { google::protobuf::ShutdownProtobufLibrary(); } + ProtobufGlobalSymbolGuard(const ProtobufGlobalSymbolGuard &) = delete; + ProtobufGlobalSymbolGuard &operator=(const ProtobufGlobalSymbolGuard &) = delete; + ProtobufGlobalSymbolGuard(ProtobufGlobalSymbolGuard &&) = delete; + ProtobufGlobalSymbolGuard &operator=(ProtobufGlobalSymbolGuard &&) = delete; }; template diff --git a/exporters/otlp/test/otlp_grpc_exporter_test.cc b/exporters/otlp/test/otlp_grpc_exporter_test.cc index 365d98cecd..f7fb612394 100644 --- a/exporters/otlp/test/otlp_grpc_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_exporter_test.cc @@ -75,8 +75,6 @@ class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceSe public: async_interface(OtlpMockTraceServiceStub *owner) : stub_(owner) {} - virtual ~async_interface() override = default; - void Export( ::grpc::ClientContext *context, const ::opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest *request, diff --git a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc index e7836a3d8e..5b4600a1e2 100644 --- a/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc @@ -125,8 +125,6 @@ class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceSe public: async_interface(OtlpMockTraceServiceStub *owner) : stub_(owner) {} - ~async_interface() override = default; - void Export( ::grpc::ClientContext *context, const ::opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest *request, @@ -188,8 +186,6 @@ class OtlpMockLogsServiceStub : public proto::collector::logs::v1::MockLogsServi public: async_interface(OtlpMockLogsServiceStub *owner) : stub_(owner) {} - ~async_interface() override = default; - void Export( ::grpc::ClientContext *context, const ::opentelemetry::proto::collector::logs::v1::ExportLogsServiceRequest *request, diff --git a/exporters/otlp/test/otlp_metrics_serialization_test.cc b/exporters/otlp/test/otlp_metrics_serialization_test.cc index 4079931d44..00116de998 100644 --- a/exporters/otlp/test/otlp_metrics_serialization_test.cc +++ b/exporters/otlp/test/otlp_metrics_serialization_test.cc @@ -12,7 +12,6 @@ #include "opentelemetry/exporters/otlp/otlp_metric_utils.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/nostd/unique_ptr.h" -#include "opentelemetry/nostd/variant.h" #include "opentelemetry/sdk/common/attribute_utils.h" #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" #include "opentelemetry/sdk/metrics/data/circular_buffer.h" diff --git a/ext/test/http/curl_http_test.cc b/ext/test/http/curl_http_test.cc index f178332e8b..5337af8a68 100644 --- a/ext/test/http/curl_http_test.cc +++ b/ext/test/http/curl_http_test.cc @@ -64,8 +64,6 @@ class CustomEventHandler : public http_client::EventHandler CustomEventHandler() : is_called_(false), got_response_(false) {} - ~CustomEventHandler() override = default; - std::atomic is_called_; std::atomic got_response_; }; @@ -700,8 +698,6 @@ TEST_F(BasicCurlHttpTests, BackgroundThreadWaitMore) #ifdef ENABLE_OTLP_COMPRESSION_PREVIEW struct GzipEventHandler : public CustomEventHandler { - ~GzipEventHandler() override = default; - void OnResponse(http_client::Response & /* response */) noexcept override {} void OnEvent(http_client::SessionState state, nostd::string_view reason) noexcept override diff --git a/sdk/include/opentelemetry/sdk/common/global_log_handler.h b/sdk/include/opentelemetry/sdk/common/global_log_handler.h index 7930edcce1..b700b9e398 100644 --- a/sdk/include/opentelemetry/sdk/common/global_log_handler.h +++ b/sdk/include/opentelemetry/sdk/common/global_log_handler.h @@ -58,7 +58,12 @@ inline std::string LevelToString(LogLevel level) class LogHandler { public: + LogHandler() = default; virtual ~LogHandler(); + LogHandler(const LogHandler &) = default; + LogHandler(LogHandler &&) = default; + LogHandler &operator=(const LogHandler &) = default; + LogHandler &operator=(LogHandler &&) = default; virtual void Handle(LogLevel level, const char *file, diff --git a/sdk/include/opentelemetry/sdk/metrics/data/point_data.h b/sdk/include/opentelemetry/sdk/metrics/data/point_data.h index df14e2d099..e2afc6f161 100644 --- a/sdk/include/opentelemetry/sdk/metrics/data/point_data.h +++ b/sdk/include/opentelemetry/sdk/metrics/data/point_data.h @@ -25,10 +25,12 @@ class SumPointData { public: // TODO: remove ctors and initializers when GCC<5 stops shipping on Ubuntu - SumPointData(SumPointData &&) = default; - SumPointData(const SumPointData &) = default; - SumPointData &operator=(SumPointData &&) = default; - SumPointData() = default; + SumPointData(SumPointData &&) = default; + SumPointData(const SumPointData &) = default; + SumPointData &operator=(SumPointData &&) = default; + SumPointData() = default; + SumPointData &operator=(const SumPointData &other) = default; + ~SumPointData() = default; ValueType value_ = {}; bool is_monotonic_ = true; @@ -38,10 +40,12 @@ class LastValuePointData { public: // TODO: remove ctors and initializers when GCC<5 stops shipping on Ubuntu - LastValuePointData(LastValuePointData &&) = default; - LastValuePointData(const LastValuePointData &) = default; - LastValuePointData &operator=(LastValuePointData &&) = default; - LastValuePointData() = default; + LastValuePointData(LastValuePointData &&) = default; + LastValuePointData(const LastValuePointData &) = default; + LastValuePointData &operator=(LastValuePointData &&) = default; + LastValuePointData() = default; + LastValuePointData &operator=(const LastValuePointData &other) = default; + ~LastValuePointData() = default; ValueType value_ = {}; bool is_lastvalue_valid_ = {}; @@ -57,6 +61,9 @@ class HistogramPointData HistogramPointData(const HistogramPointData &) = default; HistogramPointData() = default; HistogramPointData(std::vector &boundaries) : boundaries_(boundaries) {} + HistogramPointData &operator=(const HistogramPointData &other) = default; + ~HistogramPointData() = default; + std::vector boundaries_ = {}; ValueType sum_ = {}; ValueType min_ = {}; diff --git a/sdk/test/common/global_log_handle_singleton_lifetime_test.cc b/sdk/test/common/global_log_handle_singleton_lifetime_test.cc index 95a1f8cf97..1aac3ee412 100644 --- a/sdk/test/common/global_log_handle_singleton_lifetime_test.cc +++ b/sdk/test/common/global_log_handle_singleton_lifetime_test.cc @@ -50,6 +50,12 @@ static GlobalLogHandlerChecker &ConstructChecker() class CustomLogHandler : public opentelemetry::sdk::common::internal_log::LogHandler { public: + CustomLogHandler() = default; + CustomLogHandler(const CustomLogHandler &) = default; + CustomLogHandler(CustomLogHandler &&) = default; + CustomLogHandler &operator=(const CustomLogHandler &) = default; + CustomLogHandler &operator=(CustomLogHandler &&) = default; + ~CustomLogHandler() override { GlobalLogHandlerChecker::custom_handler_destroyed = true; diff --git a/sdk/test/metrics/meter_test.cc b/sdk/test/metrics/meter_test.cc index 002c2a665a..a4212996a3 100644 --- a/sdk/test/metrics/meter_test.cc +++ b/sdk/test/metrics/meter_test.cc @@ -192,8 +192,7 @@ class MeterCreateInstrumentTest : public ::testing::Test class TestProcessor : public sdk::metrics::AttributesProcessor { public: - explicit TestProcessor() = default; - ~TestProcessor() override = default; + explicit TestProcessor() = default; sdk::metrics::MetricAttributes process( const opentelemetry::common::KeyValueIterable &attributes) const noexcept override