Skip to content

Commit a134a0e

Browse files
authored
[CODE HEALTH] turn on the cppcoreguidelines-init-variables check and fix warnings (open-telemetry#3751)
1 parent d6301b7 commit a134a0e

29 files changed

+166
-181
lines changed

.clang-tidy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ Checks: >
3535
-cppcoreguidelines-avoid-do-while,
3636
-cppcoreguidelines-avoid-c-arrays,
3737
-cppcoreguidelines-avoid-magic-numbers,
38-
-cppcoreguidelines-init-variables,
3938
-cppcoreguidelines-macro-usage,
4039
-cppcoreguidelines-non-private-member-variables-in-classes,
4140
-cppcoreguidelines-avoid-non-const-global-variables,

api/test/common/kv_properties_test.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ using opentelemetry::common::KeyValueStringTokenizerOptions;
6666

6767
TEST(KVStringTokenizer, SinglePair)
6868
{
69-
bool valid_kv;
69+
bool valid_kv{};
7070
nostd::string_view key, value;
7171
opentelemetry::nostd::string_view str = "k1=v1";
7272
KeyValueStringTokenizerOptions opts;
@@ -80,7 +80,7 @@ TEST(KVStringTokenizer, SinglePair)
8080

8181
TEST(KVStringTokenizer, AcceptEmptyEntries)
8282
{
83-
bool valid_kv;
83+
bool valid_kv{};
8484
nostd::string_view key, value;
8585
opentelemetry::nostd::string_view str = ":k1=v1::k2=v2: ";
8686
KeyValueStringTokenizerOptions opts;
@@ -104,7 +104,7 @@ TEST(KVStringTokenizer, AcceptEmptyEntries)
104104
TEST(KVStringTokenizer, ValidPairsWithEmptyEntries)
105105
{
106106
opentelemetry::nostd::string_view str = "k1:v1===k2:v2==";
107-
bool valid_kv;
107+
bool valid_kv{};
108108
nostd::string_view key, value;
109109
KeyValueStringTokenizerOptions opts;
110110
opts.member_separator = '=';
@@ -128,7 +128,7 @@ TEST(KVStringTokenizer, InvalidPairs)
128128
{
129129
opentelemetry::nostd::string_view str = "k1=v1,invalid ,, k2=v2 ,invalid";
130130
KeyValueStringTokenizer tk(str);
131-
bool valid_kv;
131+
bool valid_kv{};
132132
nostd::string_view key, value;
133133
EXPECT_TRUE(tk.next(valid_kv, key, value));
134134

api/test/nostd/shared_ptr_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ TEST(SharedPtrTest, MoveConstructionFromStdSharedPtr)
9898

9999
TEST(SharedPtrTest, Destruction)
100100
{
101-
bool was_destructed;
101+
bool was_destructed{};
102102
shared_ptr<A>{new A{was_destructed}}; // NOLINT
103103
EXPECT_TRUE(was_destructed);
104104
}

api/test/nostd/unique_ptr_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ TEST(UniquePtrTest, MoveConstructionFromStdUniquePtr)
8181

8282
TEST(UniquePtrTest, Destruction)
8383
{
84-
bool was_destructed;
84+
bool was_destructed{};
8585
unique_ptr<A>{new A{was_destructed}}; // NOLINT
8686
EXPECT_TRUE(was_destructed);
8787
}
@@ -127,7 +127,7 @@ TEST(UniquePtrTest, PointerOperators)
127127

128128
TEST(UniquePtrTest, Reset)
129129
{
130-
bool was_destructed1;
130+
bool was_destructed1{};
131131
unique_ptr<A> ptr{new A{was_destructed1}};
132132
bool was_destructed2 = true;
133133
ptr.reset(new A{was_destructed2});

ci/do_ci.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,21 @@ elif [[ "$1" == "cmake.legacy.test" ]]; then
338338
make -j $(nproc)
339339
make test
340340
exit 0
341+
elif [[ "$1" == "cmake.clang_tidy.test" ]]; then
342+
cd "${BUILD_DIR}"
343+
rm -rf *
344+
export BUILD_ROOT="${BUILD_DIR}"
345+
cmake -S ${SRC_DIR} \
346+
-B ${BUILD_DIR} \
347+
-C ${SRC_DIR}/test_common/cmake/all-options-abiv2-preview.cmake \
348+
"${CMAKE_OPTIONS[@]}" \
349+
-DWITH_OPENTRACING=OFF \
350+
-DCMAKE_CXX_FLAGS="-Wno-deprecated-declarations" \
351+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
352+
-DCMAKE_CXX_CLANG_TIDY="clang-tidy;--quiet;-p;${BUILD_DIR}"
353+
make -j $(nproc)
354+
make test
355+
exit 0
341356
elif [[ "$1" == "cmake.legacy.exporter.otprotocol.test" ]]; then
342357
cd "${BUILD_DIR}"
343358
rm -rf *

examples/grpc/client.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,12 @@ int main(int argc, char **argv)
127127
opentelemetry::nostd::shared_ptr<context::propagation::TextMapPropagator>(
128128
new propagation::HttpTraceContext()));
129129
constexpr uint16_t default_port = 8800;
130-
uint16_t port;
130+
uint16_t port{default_port};
131131
if (argc > 1)
132132
{
133133
port = static_cast<uint16_t>(atoi(argv[1]));
134134
}
135-
else
136-
{
137-
port = default_port;
138-
}
135+
139136
RunClient(port);
140137
CleanupTracer();
141138
return 0;

examples/grpc/server.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,11 @@ int main(int argc, char **argv)
127127
{
128128
InitTracer();
129129
constexpr uint16_t default_port = 8800;
130-
uint16_t port;
130+
uint16_t port{default_port};
131131
if (argc > 1)
132132
{
133133
port = static_cast<uint16_t>(atoi(argv[1]));
134134
}
135-
else
136-
{
137-
port = default_port;
138-
}
139135

140136
RunServer(port);
141137
CleanupTracer();

examples/http/client.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,13 @@ int main(int argc, char *argv[])
9999
constexpr char default_host[] = "localhost";
100100
constexpr char default_path[] = "/helloworld";
101101
constexpr uint16_t default_port = 8800;
102-
uint16_t port;
102+
uint16_t port{default_port};
103103

104104
// The port the validation service listens to can be specified via the command line.
105105
if (argc > 1)
106106
{
107107
port = static_cast<uint16_t>(atoi(argv[1]));
108108
}
109-
else
110-
{
111-
port = default_port;
112-
}
113109

114110
std::string url = "http://" + std::string(default_host) + ":" + std::to_string(port) +
115111
std::string(default_path);

exporters/ostream/src/console_push_metric_builder.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ void ConsolePushMetricBuilder::Register(opentelemetry::sdk::configuration::Regis
3131
std::unique_ptr<opentelemetry::sdk::metrics::PushMetricExporter> ConsolePushMetricBuilder::Build(
3232
const opentelemetry::sdk::configuration::ConsolePushMetricExporterConfiguration *model) const
3333
{
34-
sdk::metrics::AggregationTemporality aggregation_temporality;
34+
sdk::metrics::AggregationTemporality aggregation_temporality{
35+
sdk::metrics::AggregationTemporality::kUnspecified};
3536

3637
switch (model->temporality_preference)
3738
{

0 commit comments

Comments
 (0)