Skip to content

Commit 54856de

Browse files
authored
Add -Wsign-conversion -Wsign-promo compiler flags (#43)
* Add `-Wsign-conversion -Wsign-promo` compiler flags * chore: Update to Visual Studio 22 to match GitHub windows-latest image Co-authored-by: David Sze <[email protected]>
1 parent c42eb8b commit 54856de

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

.github/workflows/windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
choco install cmake
1212
- name: build
1313
run: |
14-
cmake -S . -B build -G "Visual Studio 16 2019" -A x64
14+
cmake -S . -B build -G "Visual Studio 17 2022" -A x64
1515
cmake --build build --target ALL_BUILD --config Release
1616
- name: test
1717
run: |

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ if(ENABLE_TESTS)
7070
if(WIN32)
7171
target_compile_options(testStatsdClient PRIVATE -W4 -WX /external:W0)
7272
else()
73-
target_compile_options(testStatsdClient PRIVATE -Wall -Wextra -pedantic -Werror)
73+
target_compile_options(testStatsdClient PRIVATE -Wall -Wextra -pedantic -Werror -Wsign-conversion -Wsign-promo)
7474
endif()
7575
target_include_directories(testStatsdClient PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests)
7676
target_link_libraries(testStatsdClient ${PROJECT_NAME})

include/cpp-statsd-client/StatsdClient.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class StatsdClient {
6666
const std::string& prefix,
6767
const uint64_t batchsize = 0,
6868
const uint64_t sendInterval = 1000,
69-
const unsigned int gaugePrecision = 4) noexcept;
69+
const int gaugePrecision = 4) noexcept;
7070

7171
StatsdClient(const StatsdClient&) = delete;
7272
StatsdClient& operator=(const StatsdClient&) = delete;
@@ -82,7 +82,7 @@ class StatsdClient {
8282
const std::string& prefix,
8383
const uint64_t batchsize = 0,
8484
const uint64_t sendInterval = 1000,
85-
const unsigned int gaugePrecision = 4) noexcept;
85+
const int gaugePrecision = 4) noexcept;
8686

8787
//! Returns the error message as an std::string
8888
const std::string& errorMessage() const noexcept;
@@ -158,7 +158,7 @@ class StatsdClient {
158158
mutable std::string m_buffer;
159159

160160
//! Fixed floating point precision of gauges
161-
unsigned int m_gaugePrecision;
161+
int m_gaugePrecision;
162162
};
163163

164164
namespace detail {
@@ -182,7 +182,7 @@ inline StatsdClient::StatsdClient(const std::string& host,
182182
const std::string& prefix,
183183
const uint64_t batchsize,
184184
const uint64_t sendInterval,
185-
const unsigned int gaugePrecision) noexcept
185+
const int gaugePrecision) noexcept
186186
: m_prefix(detail::sanitizePrefix(prefix)),
187187
m_sender(new UDPSender{host, port, batchsize, sendInterval}),
188188
m_gaugePrecision(gaugePrecision) {
@@ -197,7 +197,7 @@ inline void StatsdClient::setConfig(const std::string& host,
197197
const std::string& prefix,
198198
const uint64_t batchsize,
199199
const uint64_t sendInterval,
200-
const unsigned int gaugePrecision) noexcept {
200+
const int gaugePrecision) noexcept {
201201
m_prefix = detail::sanitizePrefix(prefix);
202202
m_sender.reset(new UDPSender(host, port, batchsize, sendInterval));
203203
m_gaugePrecision = gaugePrecision;

include/cpp-statsd-client/UDPSender.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ inline void UDPSender::sendToDaemon(const std::string& message) noexcept {
320320
(struct sockaddr*)&m_server,
321321
sizeof(m_server));
322322
if (ret == -1) {
323-
m_errorMessage = "sendto server failed: host=" + m_host + ":" + std::to_string(m_port) +
324-
", err=" + std::to_string(SOCKET_ERRNO);
323+
m_errorMessage = "sendto server failed: host=" + m_host + ":" +
324+
std::to_string(static_cast<unsigned int>(m_port)) + ", err=" + std::to_string(SOCKET_ERRNO);
325325
}
326326
}
327327

tests/StatsdServer.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ class StatsdServer {
5959
// Try to receive (this is blocking)
6060
std::string buffer(256, '\0');
6161
int string_len;
62+
#ifdef _WIN32
6263
if ((string_len = recv(m_socket, &buffer[0], static_cast<int>(buffer.size()), 0)) < 1) {
64+
#else
65+
if ((string_len = recv(m_socket, &buffer[0], buffer.size(), 0)) < 1) {
66+
#endif
6367
m_errorMessage = "Could not recv on the socket file descriptor";
6468
return "";
6569
}

0 commit comments

Comments
 (0)