Skip to content

Commit ad2f0bd

Browse files
committed
FIX: Fix warnings on Windows
1 parent 8472c8c commit ad2f0bd

16 files changed

+127
-48
lines changed

CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_BUILD_TYPE STREQUAL "Debug")
110110
target_compile_options(${PROJECT_NAME} PRIVATE -fstandalone-debug)
111111
endif()
112112

113-
verbose_message("Applied compiler warnings.")
114-
115113
#
116114
# Model project dependencies
117115
#

CompilerWarnings.cmake

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# from here:
2+
#
3+
# https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md
4+
# Courtesy of Jason Turner
5+
6+
function(set_target_warnings target)
7+
set(MSVC_WARNINGS
8+
/w14263 # 'function': member function does not override any base class
9+
# virtual member function
10+
/w14265 # 'classname': class has virtual functions, but destructor is not
11+
# virtual instances of this class may not be destructed correctly
12+
/w14287 # 'operator': unsigned/negative constant mismatch
13+
/we4289 # nonstandard extension used: 'variable': loop control variable
14+
# declared in the for-loop is used outside the for-loop scope
15+
/w14296 # 'operator': expression is always 'boolean_value'
16+
/w14311 # 'variable': pointer truncation from 'type1' to 'type2'
17+
/w14545 # expression before comma evaluates to a function which is missing
18+
# an argument list
19+
/w14546 # function call before comma missing argument list
20+
/w14547 # 'operator': operator before comma has no effect; expected
21+
# operator with side-effect
22+
/w14549 # 'operator': operator before comma has no effect; did you intend
23+
# 'operator'?
24+
/w14555 # expression has no effect; expected expression with side- effect
25+
/w14619 # pragma warning: there is no warning number 'number'
26+
/w14640 # Enable warning on thread un-safe static member initialization
27+
/w14826 # Conversion from 'type1' to 'type_2' is sign-extended. This may
28+
# cause unexpected runtime behavior.
29+
/w14905 # wide string literal cast to 'LPSTR'
30+
/w14906 # string literal cast to 'LPWSTR'
31+
/w14928 # illegal copy-initialization; more than one user-defined
32+
# conversion has been implicitly applied
33+
/permissive- # standards conformance mode for MSVC compiler.
34+
)
35+
36+
set(CLANG_WARNINGS
37+
-Wall
38+
-Wextra # reasonable and standard
39+
-Wshadow # warn the user if a variable declaration shadows one from a
40+
# parent context
41+
-Wnon-virtual-dtor # warn the user if a class with virtual functions has a
42+
# non-virtual destructor. This helps catch hard to
43+
# track down memory errors
44+
-Wold-style-cast # warn for c-style casts
45+
-Wcast-align # warn for potential performance problem casts
46+
-Wunused # warn on anything being unused
47+
-Woverloaded-virtual # warn if you overload (not override) a virtual
48+
# function
49+
-Wpedantic # warn if non-standard C++ is used
50+
-Wconversion # warn on type conversions that may lose data
51+
-Wsign-conversion # warn on sign conversions
52+
-Wnull-dereference # warn if a null dereference is detected
53+
-Wdouble-promotion # warn if float is implicit promoted to double
54+
-Wformat=2 # warn on security issues around functions that format output
55+
# (ie printf)
56+
-Wimplicit-fallthrough # warn on switch labels without break
57+
)
58+
59+
set(GCC_WARNINGS
60+
${CLANG_WARNINGS}
61+
-Wmisleading-indentation # warn if indentation implies blocks where blocks
62+
# do not exist
63+
-Wduplicated-cond # warn if if / else chain has duplicated conditions
64+
-Wduplicated-branches # warn if if / else branches have duplicated code
65+
-Wlogical-op # warn about logical operations being used where bitwise were
66+
# probably wanted
67+
-Wuseless-cast # warn if you perform a cast to the same type
68+
-Wno-ignored-attributes
69+
-Wno-dangling-reference # False positives with nlohmann_json
70+
)
71+
72+
if (${PROJECT_NAME}_WARNINGS_AS_ERRORS)
73+
set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror)
74+
set(GCC_WARNINGS ${GCC_WARNINGS} -Werror)
75+
set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX)
76+
endif()
77+
78+
if(MSVC)
79+
set(WARNINGS ${MSVC_WARNINGS})
80+
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
81+
set(WARNINGS ${CLANG_WARNINGS})
82+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
83+
set(WARNINGS ${GCC_WARNINGS})
84+
else()
85+
message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.")
86+
endif()
87+
88+
target_compile_options(${target} PRIVATE ${WARNINGS})
89+
endfunction()

include/databento/batch.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
#pragma once
22

3-
#include <cstddef>
43
#include <cstdint>
54
#include <ostream>
65
#include <string>
76
#include <vector>
87

9-
#include "databento/datetime.hpp" // UnixNanos
108
#include "databento/enums.hpp" // JobState, Delivery, Packaging, Schema, SType
119

1210
namespace databento {

include/databento/historical.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ class Historical {
241241
DbnFileStore TimeseriesGetRangeToFile(const HttplibParams& params,
242242
const std::string& file_path);
243243

244-
ILogReceiver* log_receiver_;
245244
const std::string key_;
246245
const std::string gateway_;
247246
detail::HttpClient client_;

include/databento/live.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22

3-
#include <cstdint>
43
#include <string>
54

65
#include "databento/enums.hpp" // VersionUpgradePolicy

include/databento/live_blocking.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <array>
44
#include <chrono> // milliseconds
55
#include <cstdint>
6-
#include <memory>
76
#include <string>
87
#include <vector>
98

include/databento/live_threaded.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
#include <vector>
88

99
#include "databento/datetime.hpp" // UnixNanos
10-
#include "databento/dbn.hpp" // Metadata
1110
#include "databento/detail/scoped_thread.hpp" // ScopedThread
1211
#include "databento/enums.hpp" // Schema, SType
13-
#include "databento/record.hpp" // Record
1412
#include "databento/timeseries.hpp" // MetadataCallback, RecordCallback
1513

1614
namespace databento {

include/databento/metadata.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <map>
55
#include <ostream>
66
#include <string>
7-
#include <vector>
87

98
#include "databento/enums.hpp" // FeedMode, DatasetCondition, Schema
109

include/databento/symbology.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22

3-
#include <cstdint>
43
#include <ostream>
54
#include <string>
65
#include <unordered_map>

src/datetime.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ std::string ToIso8601(UnixNanos unix_nanos) {
1717
return "UNDEF_TIMESTAMP";
1818
}
1919
std::array<char, 80> buf{};
20-
const auto time =
21-
static_cast<std::time_t>(std::chrono::duration_cast<std::chrono::seconds>(
22-
unix_nanos.time_since_epoch())
23-
.count());
20+
const std::time_t time = std::chrono::duration_cast<std::chrono::seconds>(
21+
unix_nanos.time_since_epoch())
22+
.count();
2423
std::tm tm = {};
2524
#ifdef _WIN32
2625
if (::gmtime_s(&tm, &time) != 0) {

src/historical.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,13 @@ std::string PathJoin(const std::string& dir, const std::string& path) {
148148

149149
Historical::Historical(ILogReceiver* log_receiver, std::string key,
150150
HistoricalGateway gateway)
151-
: log_receiver_{log_receiver},
152-
key_{std::move(key)},
151+
: key_{std::move(key)},
153152
gateway_{UrlFromGateway(gateway)},
154153
client_{log_receiver, key_, gateway_} {}
155154

156155
Historical::Historical(ILogReceiver* log_receiver, std::string key,
157156
std::string gateway, std::uint16_t port)
158-
: log_receiver_{log_receiver},
159-
key_{std::move(key)},
157+
: key_{std::move(key)},
160158
gateway_{std::move(gateway)},
161159
client_{log_receiver, key_, gateway_, port} {}
162160

@@ -908,7 +906,7 @@ void Historical::TimeseriesGetRange(const HttplibParams& params,
908906
break;
909907
}
910908
}
911-
} catch (const std::exception& exc) {
909+
} catch (const std::exception&) {
912910
should_continue = false;
913911
// wait for thread to finish before checking for exceptions
914912
stream.Join();

src/live_threaded.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ using databento::LiveThreaded;
1717

1818
struct LiveThreaded::Impl {
1919
template <typename... A>
20-
explicit Impl(ILogReceiver* log_receiver, A&&... args)
21-
: log_receiver{log_receiver},
20+
explicit Impl(ILogReceiver* log_recv, A&&... args)
21+
: log_receiver{log_recv},
2222
blocking{log_receiver, std::forward<A>(args)...} {}
2323

2424
void NotifyOfStop() {

test/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ set(
5151
src/zstd_stream_tests.cpp
5252
)
5353
add_executable(${PROJECT_NAME} ${test_headers} ${test_sources})
54+
if(WIN32)
55+
# Disable warnings
56+
target_compile_options(${PROJECT_NAME} PRIVATE /w)
57+
endif()
5458
find_package(Threads REQUIRED)
5559

5660
target_link_libraries(

test/src/live_blocking_tests.cpp

+16-13
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ TEST_F(LiveBlockingTests, TestSubscribe) {
7171
constexpr auto kTsOut = false;
7272
constexpr auto kDataset = dataset::kXnasItch;
7373
const std::vector<std::string> kSymbols{"MSFT", "TSLA", "QQQ"};
74-
constexpr auto kSchema = Schema::Ohlcv1M;
75-
constexpr auto kSType = SType::RawSymbol;
74+
const auto kSchema = Schema::Ohlcv1M;
75+
const auto kSType = SType::RawSymbol;
7676

7777
const mock::MockLsgServer mock_server{
78-
kDataset, kTsOut, [&kSymbols](mock::MockLsgServer& self) {
78+
kDataset, kTsOut,
79+
[&kSymbols, kSchema, kSType](mock::MockLsgServer& self) {
7980
self.Accept();
8081
self.Authenticate();
8182
self.Subscribe(kSymbols, kSchema, kSType);
@@ -94,13 +95,14 @@ TEST_F(LiveBlockingTests, TestSubscribe) {
9495
TEST_F(LiveBlockingTests, TestSubscriptionChunking) {
9596
constexpr auto kTsOut = false;
9697
constexpr auto kDataset = dataset::kXnasItch;
97-
constexpr auto kSymbol = "TEST";
98-
constexpr std::size_t kSymbolCount = 1000;
99-
constexpr auto kSchema = Schema::Ohlcv1M;
100-
constexpr auto kSType = SType::RawSymbol;
98+
const auto kSymbol = "TEST";
99+
const std::size_t kSymbolCount = 1000;
100+
const auto kSchema = Schema::Ohlcv1M;
101+
const auto kSType = SType::RawSymbol;
101102

102103
const mock::MockLsgServer mock_server{
103-
kDataset, kTsOut, [](mock::MockLsgServer& self) {
104+
kDataset, kTsOut,
105+
[kSymbol, kSymbolCount, kSchema, kSType](mock::MockLsgServer& self) {
104106
self.Accept();
105107
self.Authenticate();
106108
std::size_t i{};
@@ -126,10 +128,10 @@ TEST_F(LiveBlockingTests, TestSubscriptionChunking) {
126128

127129
TEST_F(LiveBlockingTests, TestNextRecord) {
128130
constexpr auto kTsOut = false;
129-
constexpr auto kRecCount = 12;
131+
const auto kRecCount = 12;
130132
constexpr OhlcvMsg kRec{DummyHeader<OhlcvMsg>(RType::Ohlcv1M), 1, 2, 3, 4, 5};
131133
const mock::MockLsgServer mock_server{
132-
dataset::kXnasItch, kTsOut, [kRec](mock::MockLsgServer& self) {
134+
dataset::kXnasItch, kTsOut, [kRec, kRecCount](mock::MockLsgServer& self) {
133135
self.Accept();
134136
self.Authenticate();
135137
for (size_t i = 0; i < kRecCount; ++i) {
@@ -264,7 +266,7 @@ TEST_F(LiveBlockingTests, TestNextRecordPartialRead) {
264266
}
265267

266268
TEST_F(LiveBlockingTests, TestNextRecordWithTsOut) {
267-
constexpr auto kRecCount = 5;
269+
const auto kRecCount = 5;
268270
constexpr auto kTsOut = true;
269271
const WithTsOut<TradeMsg> send_rec{
270272
{DummyHeader<TradeMsg>(RType::Mbp0),
@@ -279,7 +281,8 @@ TEST_F(LiveBlockingTests, TestNextRecordWithTsOut) {
279281
2},
280282
UnixNanos{std::chrono::seconds{1678910279000000000}}};
281283
const mock::MockLsgServer mock_server{
282-
dataset::kXnasItch, kTsOut, [send_rec](mock::MockLsgServer& self) {
284+
dataset::kXnasItch, kTsOut,
285+
[send_rec, kRecCount](mock::MockLsgServer& self) {
283286
self.Accept();
284287
self.Authenticate();
285288
for (size_t i = 0; i < kRecCount; ++i) {
@@ -331,7 +334,7 @@ TEST_F(LiveBlockingTests, TestStop) {
331334
static_cast<::ssize_t>(rec_str.size())) {
332335
}
333336
}} // namespace test
334-
}; // namespace databento
337+
}; // namespace databento
335338

336339
LiveBlocking target{
337340
logger_.get(), kKey, dataset::kXnasItch, kLocalhost,

test/src/live_threaded_tests.cpp

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include <gtest/gtest.h>
22

3-
#include <algorithm>
43
#include <atomic>
54
#include <cstdint>
65
#include <exception>
@@ -184,8 +183,8 @@ TEST_F(LiveThreadedTests, TestExceptionCallbackAndReconnect) {
184183
std::condition_variable should_close_cv;
185184
const mock::MockLsgServer mock_server{
186185
dataset::kXnasItch, kTsOut,
187-
[&should_close, &should_close_mutex, &should_close_cv,
188-
kRec](mock::MockLsgServer& self) {
186+
[&should_close, &should_close_mutex, &should_close_cv, kRec, kSchema,
187+
kSType](mock::MockLsgServer& self) {
189188
self.Accept();
190189
self.Authenticate();
191190
self.Subscribe(kAllSymbols, kSchema, kSType);
@@ -222,8 +221,8 @@ TEST_F(LiveThreadedTests, TestExceptionCallbackAndReconnect) {
222221
return KeepGoing::Stop;
223222
};
224223
std::atomic<std::int32_t> exception_calls{};
225-
const auto exception_cb = [&exception_calls,
226-
&target](const std::exception& exc) {
224+
const auto exception_cb = [&exception_calls, &target, kSchema,
225+
kSType](const std::exception& exc) {
227226
++exception_calls;
228227
if (exception_calls == 1) {
229228
EXPECT_NE(dynamic_cast<const databento::DbnResponseError*>(&exc), nullptr)
@@ -245,8 +244,8 @@ TEST_F(LiveThreadedTests, TestExceptionCallbackAndReconnect) {
245244
}
246245

247246
TEST_F(LiveThreadedTests, TestDeadlockPrevention) {
248-
constexpr auto kSchema = Schema::Trades;
249-
constexpr auto kSType = SType::Parent;
247+
const auto kSchema = Schema::Trades;
248+
const auto kSType = SType::Parent;
250249
const std::vector<std::string> kSymbols = {"LO.OPT", "6E.FUT"};
251250

252251
bool should_close{};
@@ -255,8 +254,8 @@ TEST_F(LiveThreadedTests, TestDeadlockPrevention) {
255254
testing::internal::CaptureStderr();
256255
const mock::MockLsgServer mock_server{
257256
dataset::kXnasItch, kTsOut,
258-
[&kSymbols, &should_close, &should_close_mutex,
259-
&should_close_cv](mock::MockLsgServer& self) {
257+
[&kSymbols, &should_close, &should_close_mutex, &should_close_cv, kSchema,
258+
kSType](mock::MockLsgServer& self) {
260259
self.Accept();
261260
self.Authenticate();
262261
self.Start();
@@ -287,8 +286,8 @@ TEST_F(LiveThreadedTests, TestDeadlockPrevention) {
287286
++record_calls;
288287
return KeepGoing::Continue;
289288
};
290-
const auto exception_cb = [&target, &metadata_cb, &record_cb,
291-
&kSymbols](const std::exception& exc) {
289+
const auto exception_cb = [&target, &metadata_cb, &record_cb, &kSymbols,
290+
kSchema, kSType](const std::exception& exc) {
292291
EXPECT_NE(dynamic_cast<const databento::DbnResponseError*>(&exc), nullptr)
293292
<< "Unexpected exception type";
294293
target.Reconnect();

test/src/mock_lsg_server.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111
#include <cstdint>
1212
#include <limits>
13-
#include <sstream>
1413

15-
#include "databento/dbn.hpp"
1614
#include "databento/enums.hpp"
1715
#include "databento/exceptions.hpp"
1816
#include "databento/symbology.hpp" // JoinSymbolStrings

0 commit comments

Comments
 (0)