Skip to content

Commit 016155f

Browse files
authored
[CodeHealth] Fix clang-tidy warnings part 1 (#3493)
1 parent 1d41125 commit 016155f

22 files changed

+59
-68
lines changed

.github/workflows/clang-tidy.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ jobs:
1717
matrix:
1818
include:
1919
- cmake_options: all-options-abiv1-preview
20-
warning_limit: 215
20+
warning_limit: 172
2121
- cmake_options: all-options-abiv2-preview
22-
warning_limit: 216
22+
warning_limit: 173
2323
steps:
2424
- name: Harden the runner (Audit all outbound calls)
2525
uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ Increment the:
3030
* [REMOVAL] Removed deprecated semantic convention header files
3131
[#3475](https://github.com/open-telemetry/opentelemetry-cpp/pull/3475)
3232

33+
* [CodeHealth] Fix clang-tidy warnings part 1
34+
[#3493](https://github.com/open-telemetry/opentelemetry-cpp/pull/3493)
35+
3336
Important changes:
3437

3538
* [REMOVAL] Removed deprecated semantic convention header files

examples/otlp/grpc_metric_main.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ int main(int argc, char *argv[])
117117
}
118118
}
119119
}
120-
std::cout << "Using endpoint: " << exporter_options.endpoint << std::endl;
121-
std::cout << "Using example type: " << example_type << std::endl;
122-
std::cout << "Using cacert path: " << exporter_options.ssl_credentials_cacert_path << std::endl;
123-
std::cout << "Using ssl credentials: " << exporter_options.use_ssl_credentials << std::endl;
120+
std::cout << "Using endpoint: " << exporter_options.endpoint << "\n";
121+
std::cout << "Using example type: " << example_type << "\n";
122+
std::cout << "Using cacert path: " << exporter_options.ssl_credentials_cacert_path << "\n";
123+
std::cout << "Using ssl credentials: " << exporter_options.use_ssl_credentials << "\n";
124124

125125
// Removing this line will leave the default noop MetricProvider in place.
126126

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_client.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ class OtlpFileClient
8181
bool is_shutdown_;
8282

8383
// The configuration options associated with this file client.
84-
const OtlpFileClientOptions options_;
84+
OtlpFileClientOptions options_;
8585
// The runtime options associated with this file client.
86-
const OtlpFileClientRuntimeOptions runtime_options_;
86+
OtlpFileClientRuntimeOptions runtime_options_;
8787

8888
opentelemetry::nostd::shared_ptr<OtlpFileAppender> backend_;
8989
};

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_file_client_runtime_options.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ namespace otlp
1919
*/
2020
struct OtlpFileClientRuntimeOptions
2121
{
22-
OtlpFileClientRuntimeOptions() = default;
23-
~OtlpFileClientRuntimeOptions() = default;
24-
2522
std::shared_ptr<sdk::common::ThreadInstrumentation> thread_instrumentation =
2623
std::shared_ptr<sdk::common::ThreadInstrumentation>(nullptr);
2724
};

exporters/otlp/src/otlp_file_client.cc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -719,11 +719,11 @@ static inline char HexEncode(unsigned char byte)
719719
#endif
720720
if (byte >= 10)
721721
{
722-
return byte - 10 + 'a';
722+
return static_cast<char>(byte - 10 + 'a');
723723
}
724724
else
725725
{
726-
return byte + '0';
726+
return static_cast<char>(byte + '0');
727727
}
728728
}
729729

@@ -1004,6 +1004,11 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender
10041004
}
10051005
}
10061006

1007+
OtlpFileSystemBackend(const OtlpFileSystemBackend &) = delete;
1008+
OtlpFileSystemBackend &operator=(const OtlpFileSystemBackend &) = delete;
1009+
OtlpFileSystemBackend(OtlpFileSystemBackend &&) = delete;
1010+
OtlpFileSystemBackend &operator=(OtlpFileSystemBackend &&) = delete;
1011+
10071012
// Written size is not required to be precise, we can just ignore tsan report here.
10081013
OPENTELEMETRY_SANITIZER_NO_THREAD void MaybeRotateLog(std::size_t data_size)
10091014
{
@@ -1588,11 +1593,9 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileOstreamBackend : public OtlpFileAppende
15881593
public:
15891594
explicit OtlpFileOstreamBackend(const std::reference_wrapper<std::ostream> &os) : os_(os) {}
15901595

1591-
~OtlpFileOstreamBackend() override {}
1592-
15931596
void Export(nostd::string_view data, std::size_t /*record_count*/) override
15941597
{
1595-
os_.get().write(data.data(), data.size());
1598+
os_.get().write(data.data(), static_cast<std::streamsize>(data.size()));
15961599
}
15971600

15981601
bool ForceFlush(std::chrono::microseconds /*timeout*/) noexcept override
@@ -1611,8 +1614,8 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileOstreamBackend : public OtlpFileAppende
16111614
OtlpFileClient::OtlpFileClient(OtlpFileClientOptions &&options,
16121615
OtlpFileClientRuntimeOptions &&runtime_options)
16131616
: is_shutdown_(false),
1614-
options_(std::move(options)),
1615-
runtime_options_(std::move(runtime_options))
1617+
options_{std::move(options)},
1618+
runtime_options_{std::move(runtime_options)}
16161619
{
16171620
if (nostd::holds_alternative<OtlpFileClientFileSystemOptions>(options_.backend_options))
16181621
{

exporters/otlp/src/otlp_http_client.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class ResponseHandler : public http_client::EventHandler
175175
error_message << "[OTLP HTTP Client] Session state: session create failed.";
176176
if (!reason.empty())
177177
{
178-
error_message.write(reason.data(), reason.size());
178+
error_message.write(reason.data(), static_cast<std::streamsize>(reason.size()));
179179
}
180180
OTEL_INTERNAL_LOG_ERROR(error_message.str());
181181
}
@@ -207,7 +207,7 @@ class ResponseHandler : public http_client::EventHandler
207207
error_message << "[OTLP HTTP Client] Session state: connection failed.";
208208
if (!reason.empty())
209209
{
210-
error_message.write(reason.data(), reason.size());
210+
error_message.write(reason.data(), static_cast<std::streamsize>(reason.size()));
211211
}
212212
OTEL_INTERNAL_LOG_ERROR(error_message.str());
213213
}
@@ -232,7 +232,7 @@ class ResponseHandler : public http_client::EventHandler
232232
error_message << "[OTLP HTTP Client] Session state: request send failed.";
233233
if (!reason.empty())
234234
{
235-
error_message.write(reason.data(), reason.size());
235+
error_message.write(reason.data(), static_cast<std::streamsize>(reason.size()));
236236
}
237237
OTEL_INTERNAL_LOG_ERROR(error_message.str());
238238
}
@@ -250,7 +250,7 @@ class ResponseHandler : public http_client::EventHandler
250250
error_message << "[OTLP HTTP Client] Session state: SSL handshake failed.";
251251
if (!reason.empty())
252252
{
253-
error_message.write(reason.data(), reason.size());
253+
error_message.write(reason.data(), static_cast<std::streamsize>(reason.size()));
254254
}
255255
OTEL_INTERNAL_LOG_ERROR(error_message.str());
256256
}
@@ -261,7 +261,7 @@ class ResponseHandler : public http_client::EventHandler
261261
error_message << "[OTLP HTTP Client] Session state: request time out.";
262262
if (!reason.empty())
263263
{
264-
error_message.write(reason.data(), reason.size());
264+
error_message.write(reason.data(), static_cast<std::streamsize>(reason.size()));
265265
}
266266
OTEL_INTERNAL_LOG_ERROR(error_message.str());
267267
}
@@ -272,7 +272,7 @@ class ResponseHandler : public http_client::EventHandler
272272
error_message << "[OTLP HTTP Client] Session state: network error.";
273273
if (!reason.empty())
274274
{
275-
error_message.write(reason.data(), reason.size());
275+
error_message.write(reason.data(), static_cast<std::streamsize>(reason.size()));
276276
}
277277
OTEL_INTERNAL_LOG_ERROR(error_message.str());
278278
}
@@ -297,7 +297,7 @@ class ResponseHandler : public http_client::EventHandler
297297
error_message << "[OTLP HTTP Client] Session state: (manually) cancelled.";
298298
if (!reason.empty())
299299
{
300-
error_message.write(reason.data(), reason.size());
300+
error_message.write(reason.data(), static_cast<std::streamsize>(reason.size()));
301301
}
302302
OTEL_INTERNAL_LOG_ERROR(error_message.str());
303303
}
@@ -376,11 +376,11 @@ static inline char HexEncode(unsigned char byte)
376376
#endif
377377
if (byte >= 10)
378378
{
379-
return byte - 10 + 'a';
379+
return static_cast<char>(byte - 10 + 'a');
380380
}
381381
else
382382
{
383-
return byte + '0';
383+
return static_cast<char>(byte + '0');
384384
}
385385
}
386386

@@ -664,7 +664,7 @@ void ConvertListFieldToJson(nlohmann::json &value,
664664

665665
OtlpHttpClient::OtlpHttpClient(OtlpHttpClientOptions &&options)
666666
: is_shutdown_(false),
667-
options_(options),
667+
options_(std::move(options)),
668668
http_client_(http_client::HttpClientFactory::Create(options.thread_instrumentation)),
669669
start_session_counter_(0),
670670
finished_session_counter_(0)

sdk/include/opentelemetry/sdk/metrics/aggregation/lastvalue_aggregation.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class LongLastValueAggregation : public Aggregation
2121
{
2222
public:
2323
LongLastValueAggregation();
24-
LongLastValueAggregation(LastValuePointData &&);
2524
LongLastValueAggregation(const LastValuePointData &);
2625

2726
void Aggregate(int64_t value, const PointAttributes &attributes = {}) noexcept override;
@@ -43,16 +42,15 @@ class DoubleLastValueAggregation : public Aggregation
4342
{
4443
public:
4544
DoubleLastValueAggregation();
46-
DoubleLastValueAggregation(LastValuePointData &&);
4745
DoubleLastValueAggregation(const LastValuePointData &);
4846

4947
void Aggregate(int64_t /* value */, const PointAttributes & /* attributes */) noexcept override {}
5048

5149
void Aggregate(double value, const PointAttributes &attributes = {}) noexcept override;
5250

53-
virtual std::unique_ptr<Aggregation> Merge(const Aggregation &delta) const noexcept override;
51+
std::unique_ptr<Aggregation> Merge(const Aggregation &delta) const noexcept override;
5452

55-
virtual std::unique_ptr<Aggregation> Diff(const Aggregation &next) const noexcept override;
53+
std::unique_ptr<Aggregation> Diff(const Aggregation &next) const noexcept override;
5654

5755
PointType ToPoint() const noexcept override;
5856

sdk/include/opentelemetry/sdk/metrics/aggregation/sum_aggregation.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class LongSumAggregation : public Aggregation
2222
{
2323
public:
2424
LongSumAggregation(bool is_monotonic);
25-
LongSumAggregation(SumPointData &&);
2625
LongSumAggregation(const SumPointData &);
2726

2827
void Aggregate(int64_t value, const PointAttributes &attributes = {}) noexcept override;
@@ -44,7 +43,6 @@ class DoubleSumAggregation : public Aggregation
4443
{
4544
public:
4645
DoubleSumAggregation(bool is_monotonic);
47-
DoubleSumAggregation(SumPointData &&);
4846
DoubleSumAggregation(const SumPointData &);
4947

5048
void Aggregate(int64_t /* value */, const PointAttributes & /* attributes */) noexcept override {}

sdk/src/logs/batch_log_record_processor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void BatchLogRecordProcessor::OnEmit(std::unique_ptr<Recordable> &&record) noexc
9999
return;
100100
}
101101

102-
if (buffer_.Add(std::unique_ptr<Recordable>(record.release())) == false)
102+
if (buffer_.Add(std::move(record)) == false)
103103
{
104104
return;
105105
}

0 commit comments

Comments
 (0)