Skip to content

Commit 7a72b7a

Browse files
Increase warning level and enable warning as error (#28)
1 parent 81d33af commit 7a72b7a

29 files changed

+179
-116
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ project (signalrclient)
88

99
include(CTest)
1010

11+
set(WERROR true CACHE BOOL "Enable warnings as errors.")
12+
set(WALL true CACHE BOOL "Enable all warnings.")
13+
1114
if(NOT WIN32)
1215
set(EXTRA_FLAGS "-std=c++11 -fPIC -DNO_SIGNALRCLIENT_EXPORTS")
1316
else()

include/signalrclient/http_client.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ namespace signalr
3636
http_response() {}
3737
http_response(http_response&& rhs) noexcept : status_code(rhs.status_code), content(std::move(rhs.content)) {}
3838
http_response(int code, const std::string& content) : status_code(code), content(content) {}
39+
http_response(const http_response& rhs) : status_code(rhs.status_code), content(rhs.content) {}
40+
41+
http_response& operator=(const http_response& rhs)
42+
{
43+
status_code = rhs.status_code;
44+
content = rhs.content;
45+
46+
return *this;
47+
}
3948

4049
http_response& operator=(http_response&& rhs) noexcept
4150
{

include/signalrclient/log_writer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ namespace signalr
1313
public:
1414
// NOTE: the caller does not enforce thread safety of this call
1515
SIGNALRCLIENT_API virtual void write(const std::string &entry) = 0;
16+
17+
virtual ~log_writer() {}
1618
};
1719
}

include/signalrclient/signalr_client_config.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
#pragma once
66

77
#ifdef USE_CPPRESTSDK
8-
#include "cpprest/http_client.h"
9-
#include "cpprest/ws_client.h"
8+
#pragma warning (push)
9+
#pragma warning (disable : 5204 4355 4625 4626 4868)
10+
#include <cpprest/http_client.h>
11+
#include <cpprest/ws_client.h>
12+
#pragma warning (pop)
1013
#endif
1114

1215
#include "_exports.h"

include/signalrclient/signalr_value.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,22 @@ namespace signalr
180180
double number;
181181
std::map<std::string, value> map;
182182

183+
// constructor of types in union are not implicitly called
184+
// this is expected as we only construct a single type in the union once we know
185+
// what that type is when constructing the signalr_value type.
186+
#pragma warning (push)
187+
#pragma warning (disable: 4582)
183188
storage() {}
189+
#pragma warning (pop)
190+
191+
storage(const storage&) = delete;
192+
storage& operator=(const storage&) = delete;
193+
194+
// destructor is not implicitly called
195+
#pragma warning (push)
196+
#pragma warning (disable: 4583)
184197
~storage() {}
198+
#pragma warning (pop)
185199
};
186200

187201
storage mStorage;

src/signalrclient/CMakeLists.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,40 @@ include_directories(
3131

3232
add_library (signalrclient SHARED ${SOURCES})
3333

34+
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
35+
if(WERROR)
36+
target_compile_options(signalrclient PRIVATE /WX)
37+
endif()
38+
if(WALL)
39+
target_compile_options(signalrclient PRIVATE /Wall)
40+
endif()
41+
target_compile_options(signalrclient PRIVATE
42+
/wd4820 # padding added after data member
43+
/wd4514 # unreferenced inline function removed
44+
/wd5045 # compiler will insert Spectre mitigation if /Qspectre switch is added
45+
/wd4464 # relative include paths
46+
/wd4711 # function 'x' selected for automatic inline expansion
47+
/wd4710 # function not inlined
48+
/experimental:external /external:anglebrackets /external:templates- /external:W0
49+
/GR- # disable run-time type information
50+
/guard:cf # enable control-flow guard
51+
/EHa # enable C++ EH (w/ SEH exceptions)
52+
)
53+
else()
54+
if(WERROR)
55+
target_compile_options(signalrclient PRIVATE -Werror)
56+
endif()
57+
if(WALL)
58+
target_compile_options(signalrclient PRIVATE -Wall)
59+
endif()
60+
61+
# GCC on OSX has a bug with exceptions and no-rtti that can cause crashes
62+
if(NOT APPLE)
63+
target_compile_options(signalrclient PRIVATE -fno-rtti)
64+
endif()
65+
target_compile_options(signalrclient PRIVATE -Wextra -Wpedantic -Wno-unknown-pragmas)
66+
endif()
67+
3468
if(NOT USE_CPPRESTSDK)
3569
target_link_libraries(signalrclient)
3670
else()

src/signalrclient/cancellation_token.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ namespace signalr
2424
{
2525
}
2626

27+
cancellation_token(const cancellation_token&) = delete;
28+
cancellation_token& operator=(const cancellation_token&) = delete;
29+
2730
void cancel()
2831
{
2932
std::lock_guard<std::mutex> lock(m_lock);

src/signalrclient/case_insensitive_comparison_utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace signalr
2121
return false;
2222
}
2323

24-
for (int i = 0; i < s1.size(); ++i)
24+
for (unsigned i = 0; i < s1.size(); ++i)
2525
{
2626
if (std::toupper(s1[i]) != std::toupper(s2[i]))
2727
{
@@ -41,7 +41,7 @@ namespace signalr
4141
std::hash<size_t> hasher;
4242
for (const auto& c : s)
4343
{
44-
hash ^= hasher(std::toupper(c)) + (hash << 5) + (hash >> 2);
44+
hash ^= hasher(static_cast<size_t>(std::toupper(c))) + (hash << 5) + (hash >> 2);
4545
}
4646

4747
return hash;

src/signalrclient/completion_event.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@
44

55
#pragma once
66

7+
#pragma warning (push)
8+
#pragma warning (disable : 5204 4355)
79
#include <future>
10+
#pragma warning (pop)
811

912
namespace signalr
1013
{
1114
class completion_event_impl : public std::enable_shared_from_this<completion_event_impl>
1215
{
1316
public:
17+
completion_event_impl(const completion_event_impl&) = delete;
18+
completion_event_impl& operator=(const completion_event_impl&) = delete;
19+
1420
static std::shared_ptr<completion_event_impl> create()
1521
{
1622
return std::shared_ptr<completion_event_impl>(new completion_event_impl());

src/signalrclient/connection_impl.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,13 @@
1313
#include "signalrclient/signalr_exception.h"
1414
#include "default_http_client.h"
1515
#include "case_insensitive_comparison_utils.h"
16-
#include "make_unique.h"
1716
#include "completion_event.h"
1817
#include <assert.h>
1918
#include "signalrclient/websocket_client.h"
2019
#include "default_websocket_client.h"
2120

2221
namespace signalr
2322
{
24-
// unnamed namespace makes it invisble outside this translation unit
25-
namespace
26-
{
27-
// this is a workaround for a compiler bug where mutable lambdas won't sometimes compile
28-
static void log(const logger& logger, trace_level level, const std::string& entry);
29-
}
30-
3123
std::shared_ptr<connection_impl> connection_impl::create(const std::string& url, trace_level trace_level, const std::shared_ptr<log_writer>& log_writer)
3224
{
3325
return connection_impl::create(url, trace_level, log_writer, nullptr, nullptr);
@@ -259,8 +251,7 @@ namespace signalr
259251
}
260252
catch (const std::exception& e)
261253
{
262-
auto canceled = dynamic_cast<const canceled_exception*>(&e);
263-
if (canceled)
254+
if (token->is_canceled())
264255
{
265256
connection->m_logger.log(trace_level::info,
266257
"starting the connection has been canceled.");

0 commit comments

Comments
 (0)