Skip to content

Commit ce6b705

Browse files
author
Damien MEHALA
committed
chore(msvc): fix compilation warnings
Changes: - Treat warnings as error in CI builds for MSVC.
1 parent f3ebccc commit ce6b705

17 files changed

+111
-145
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ jobs:
116116
name: Building
117117
command: |
118118
& 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\Tools\\Launch-VsDevShell.ps1' -arch << parameters.arch >>
119-
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF -DDD_TRACE_STATIC_CRT=1 -DDD_TRACE_BUILD_TESTING=1 -G Ninja .
119+
cmake -B build -DCMAKE_COMPILE_WARNING_AS_ERROR=1 -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF -DDD_TRACE_STATIC_CRT=1 -DDD_TRACE_BUILD_TESTING=1 -G Ninja .
120120
cmake --build build -j $env:MAKE_JOB_COUNT -v
121121
- run:
122122
name: Testing

src/datadog/string_util.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ std::string join(const Sequence& elements, StringView separator,
3131

3232
void to_lower(std::string& text) {
3333
std::transform(text.begin(), text.end(), text.begin(),
34-
[](unsigned char ch) { return std::tolower(ch); });
34+
[](auto c) { return (char)std::tolower(c); });
3535
}
3636

3737
std::string to_lower(StringView sv) {
3838
std::string s;
3939
s.reserve(sv.size());
4040
std::transform(sv.begin(), sv.end(), std::back_inserter(s),
41-
[](char c) { return std::tolower(c); });
41+
[](auto c) { return (char)std::tolower(c); });
4242

4343
return s;
4444
}
@@ -47,7 +47,7 @@ std::string to_upper(StringView sv) {
4747
std::string s;
4848
s.reserve(sv.size());
4949
std::transform(sv.begin(), sv.end(), std::back_inserter(s),
50-
[](char c) { return std::toupper(c); });
50+
[](auto c) { return (char)std::toupper(c); });
5151

5252
return s;
5353
}

src/datadog/w3c_propagation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Optional<std::string> extract_traceparent(ExtractedData& result,
111111
parse_uint64(StringView(traceparent.data() + beg, 2), 16);
112112
if (maybe_trace_flags.if_error()) return "malformed_traceflags";
113113

114-
result.sampling_priority = *maybe_trace_flags & 0x01;
114+
result.sampling_priority = static_cast<int>(*maybe_trace_flags & 0x01);
115115

116116
return nullopt;
117117
}

test/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ target_include_directories(tests
5252
${CMAKE_SOURCE_DIR}/include/datadog
5353
)
5454

55+
# Enable Catch2 std stringification
56+
# <https://github.com/catchorg/Catch2/blob/devel/docs/configuration.md#enabling-stringification>
57+
target_compile_definitions(tests
58+
PUBLIC
59+
CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS
60+
)
61+
5562
target_link_libraries(tests
5663
PRIVATE
5764
# TODO: Remove dependency on libcurl

test/mocks/collectors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct MockCollectorWithResponse : public MockCollector {
6161
};
6262

6363
struct PriorityCountingCollector : public Collector {
64-
std::map<int, std::size_t> sampling_priority_count;
64+
std::map<double, std::size_t> sampling_priority_count;
6565

6666
Expected<void> send(std::vector<std::unique_ptr<SpanData>>&& spans,
6767
const std::shared_ptr<TraceSampler>&) override {

test/mocks/loggers.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ struct MockLogger : public Logger {
7878
entries.push_back(Entry{Entry::DD_ERROR, std::string(message)});
7979
}
8080

81-
int error_count() const { return count(Entry::DD_ERROR); }
81+
auto error_count() const { return count(Entry::DD_ERROR); }
8282

83-
int startup_count() const { return count(Entry::STARTUP); }
83+
auto startup_count() const { return count(Entry::STARTUP); }
8484

85-
int count(Entry::Kind kind) const {
85+
size_t count(Entry::Kind kind) const {
8686
std::lock_guard<std::mutex> lock{mutex};
8787
return std::count_if(
8888
entries.begin(), entries.end(),

test/remote_config/test_remote_config.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,14 @@ REMOTE_CONFIG_TEST("response processing") {
357357
]
358358
})";
359359

360-
const auto response_json =
360+
const auto new_response_json =
361361
nlohmann::json::parse(/* input = */ new_rc_response,
362362
/* parser_callback = */ nullptr,
363363
/* allow_exceptions = */ false);
364364

365-
REQUIRE(!response_json.is_discarded());
365+
REQUIRE(!new_response_json.is_discarded());
366366

367-
rc.process_response(response_json);
367+
rc.process_response(new_response_json);
368368

369369
CHECK(tracing_listener->count_on_update == 2);
370370
CHECK(tracing_listener->count_on_revert == 0);
@@ -398,14 +398,14 @@ REMOTE_CONFIG_TEST("response processing") {
398398
]
399399
})";
400400

401-
const auto response_json =
401+
const auto new_response_json =
402402
nlohmann::json::parse(/* input = */ rc_partial_revert_response,
403403
/* parser_callback = */ nullptr,
404404
/* allow_exceptions = */ false);
405405

406-
REQUIRE(!response_json.is_discarded());
406+
REQUIRE(!new_response_json.is_discarded());
407407

408-
rc.process_response(response_json);
408+
rc.process_response(new_response_json);
409409

410410
CHECK(tracing_listener->count_on_update == 1);
411411
CHECK(tracing_listener->count_on_revert == 1);
@@ -422,14 +422,14 @@ REMOTE_CONFIG_TEST("response processing") {
422422
"target_files": [{}]
423423
})";
424424

425-
const auto response_json =
425+
const auto new_response_json =
426426
nlohmann::json::parse(/* input = */ rc_revert_response,
427427
/* parser_callback = */ nullptr,
428428
/* allow_exceptions = */ false);
429429

430-
REQUIRE(!response_json.is_discarded());
430+
REQUIRE(!new_response_json.is_discarded());
431431

432-
rc.process_response(response_json);
432+
rc.process_response(new_response_json);
433433

434434
CHECK(tracing_listener->count_on_update == 1);
435435
CHECK(tracing_listener->count_on_revert == 1);

test/system-tests/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace dd = datadog::tracing;
1212

1313
inline std::string tolower(std::string s) {
1414
std::transform(s.begin(), s.end(), s.begin(),
15-
[](unsigned char c) { return std::tolower(c); });
15+
[](auto c) { return (char)std::tolower(c); });
1616
return s;
1717
}
1818

test/test.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
11
#include "test.h"
22

3-
namespace std {
4-
5-
std::ostream& operator<<(
6-
std::ostream& stream,
7-
const std::pair<const std::string, std::string>& item) {
8-
return stream << '{' << item.first << ", " << item.second << '}';
9-
}
10-
11-
std::ostream& operator<<(
12-
std::ostream& stream,
13-
const datadog::tracing::Optional<datadog::tracing::StringView>& item) {
14-
return stream << item.value_or("<nullopt>");
15-
}
16-
17-
std::ostream& operator<<(std::ostream& stream,
18-
const std::optional<int>& maybe) {
19-
if (maybe) {
20-
return stream << *maybe;
21-
}
22-
return stream << "<nullopt>";
23-
}
24-
25-
} // namespace std
26-
273
namespace datadog {
284
namespace tracing {
295

test/test.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,6 @@
1919

2020
#include "catch.hpp"
2121

22-
namespace std {
23-
24-
std::ostream& operator<<(std::ostream& stream,
25-
const std::pair<const std::string, std::string>& item);
26-
27-
std::ostream& operator<<(std::ostream& stream,
28-
const std::optional<std::string_view>& maybe);
29-
30-
std::ostream& operator<<(std::ostream& stream, const std::optional<int>& maybe);
31-
32-
} // namespace std
33-
3422
namespace datadog {
3523
namespace tracing {
3624

0 commit comments

Comments
 (0)