Skip to content

Commit d89e32c

Browse files
authored
Fixed numerous MSVC warnings (#76)
1 parent 3c6689d commit d89e32c

45 files changed

Lines changed: 275 additions & 215 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4040
and function signatures than normal `PhTree` filters. [#26](https://github.com/tzaeschke/phtree-cpp/issues/26)
4141

4242
### Fixed
43+
- Fixed compiler warnings when compiling with Visual Studio 2019.
44+
[#74](https://github.com/tzaeschke/phtree-cpp/issues/74)
4345
- Fixed cmake to work with Visual Studio 2019. Added tests and benchmarks to cmake.
4446
(benchmarks still do not work with VS at the moment).
4547
[#62](https://github.com/tzaeschke/phtree-cpp/issues/62)
46-
- Fixed two compilation problems and a memory leak when compiling with Visual Studio 2019.
48+
- Fixed compilation problems and a memory leak when compiling with Visual Studio 2019.
4749
(also added `msan` support). [#64](https://github.com/tzaeschke/phtree-cpp/pull/64)
4850

4951
## [1.2.0] - 2022-04-14

CMakeLists.txt

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ project(phtree VERSION 1.2.0
55
DESCRIPTION "PH-Tree C++"
66
LANGUAGES CXX)
77

8+
9+
cmake_policy(SET CMP0077 NEW)
10+
811
# ---------------------------------------------------------------------------------------
912
# Set default build to release
1013
# ---------------------------------------------------------------------------------------
@@ -33,13 +36,13 @@ option(PHTREE_BUILD_BENCHMARKS "Build benchmarks (Requires https://github.com/go
3336
# Compiler config
3437
# ---------------------------------------------------------------------------------------
3538
find_program(CCACHE_FOUND ccache)
36-
if(CCACHE_FOUND)
39+
if (CCACHE_FOUND)
3740
message("CCACHE is found")
3841
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
3942
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
40-
else(CCACHE_FOUND)
43+
else (CCACHE_FOUND)
4144
message("CCACHE is NOT found")
42-
endif(CCACHE_FOUND)
45+
endif (CCACHE_FOUND)
4346

4447
# specify the C++ standard
4548
if (NOT CMAKE_CXX_STANDARD)
@@ -48,16 +51,26 @@ if (NOT CMAKE_CXX_STANDARD)
4851
endif ()
4952

5053
if (MSVC)
51-
#set(CMAKE_CXX_FLAGS_RELEASE "/MT")
52-
#set(CMAKE_CXX_FLAGS_DEBUG "/MTd")
5354
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17 /Wall")
5455
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
5556
set(CMAKE_CXX_FLAGS_RELEASE "/O2")
5657

57-
# set(CMAKE_CXX_FLAGS "-DNOMINMAX ${CMAKE_CXX_FLAGS}") # exclude M$ min/max macros
58-
# set(CMAKE_CXX_FLAGS "/wd4996 ${CMAKE_CXX_FLAGS}") # don't warn about use of plain C functions without (non-portable) "_s" suffix
59-
# set(CMAKE_EXE_LINKER_FLAGS "/WX:NO ${CMAKE_EXE_LINKER_FLAGS}" ) # don't treat warnings as compile errors--gtest doesn't build
60-
# #set(CMAKE_CXX_FLAGS_DEBUG "/analyze ${CMAKE_CXX_FLAGS_DEBUG}")
58+
if (PHTREE_BUILD_TESTS OR PHTREE_BUILD_ALL)
59+
add_compile_options(/bigobj)
60+
endif ()
61+
62+
# For google benchmark
63+
if (PHTREE_BUILD_BENCHMARKS) # OR PHTREE_BUILD_ALL)
64+
# This still doesn't work. This also breaks gtest
65+
# See for example
66+
# https://stackoverflow.com/questions/55376111/how-to-build-and-link-google-benchmark-using-cmake-in-windows
67+
# https://github.com/google/benchmark/issues/1348
68+
# https://github.com/google/benchmark/issues/639
69+
# set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
70+
# set(BUILD_SHARED_LIBS TRUE) #=TRUE
71+
# set(BENCHMARK_DOWNLOAD_DEPENDENCIES on)
72+
# set(BENCHMARK_ENABLE_GTEST_TESTS OFF)
73+
endif ()
6174
else ()
6275
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -Werror")
6376
if (PHTREE_BUILD_BENCHMARKS)
@@ -77,7 +90,7 @@ if (PHTREE_BUILD_EXAMPLES OR PHTREE_BUILD_ALL)
7790
add_subdirectory(examples)
7891
endif ()
7992

80-
if (PHTREE_BUILD_BENCHMARKS OR PHTREE_BUILD_ALL)
93+
if (!MSVC AND (PHTREE_BUILD_BENCHMARKS OR PHTREE_BUILD_ALL))
8194
message(STATUS "Generating benchmarks")
8295
add_subdirectory(benchmark)
8396
endif ()

benchmark/benchmark_util.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ auto CreateDataCLUSTER = [](auto& points,
8181
};
8282

8383
auto CreateDuplicates =
84-
[](auto& points, size_t num_unique_entries, size_t num_total_entities, std::uint32_t seed) {
84+
[](auto& points, int num_unique_entries, size_t num_total_entities, std::uint32_t seed) {
8585
std::default_random_engine random_engine{seed};
8686
std::uniform_int_distribution<> distribution(0, num_unique_entries);
8787
for (size_t i = num_unique_entries; i < num_total_entities; ++i) {
@@ -101,11 +101,13 @@ auto CreatePointDataMinMax = [](auto& points,
101101
double world_minimum,
102102
double world_maximum,
103103
double fraction_of_duplicates) {
104-
auto set_coordinate_lambda = [](auto& p, dimension_t dim, auto value) { p[dim] = value; };
104+
auto set_coordinate_lambda = [](auto& p, dimension_t dim, auto value) {
105+
p[dim] = static_cast < typename std::remove_reference_t<decltype(p[0])>>(value);
106+
};
105107
// Create at least 1 unique point
106108
// Note that the following point generator is likely, but not guaranteed, to created unique
107109
// points.
108-
size_t num_unique_entries = 1 + (num_entities - 1) * (1. - fraction_of_duplicates);
110+
int num_unique_entries = static_cast<int>(1 + (num_entities - 1) * (1. - fraction_of_duplicates));
109111
points.reserve(num_entities);
110112
switch (test_generator) {
111113
case CUBE:
@@ -140,7 +142,7 @@ auto CreateBoxDataMinMax = [](auto& points,
140142
// Create at least 1 unique point
141143
// Note that the following point generator is likely, but not guaranteed, to created unique
142144
// points.
143-
int num_unique_entries = 1 + (num_entities - 1) * (1. - fraction_of_duplicates);
145+
int num_unique_entries = static_cast<int>(1 + (num_entities - 1) * (1. - fraction_of_duplicates));
144146
points.reserve(num_entities);
145147
switch (test_generator) {
146148
case CUBE:

benchmark/erase_benchmark.cc

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ using namespace improbable::phtree::phbenchmark;
2626
namespace {
2727

2828
const int GLOBAL_MAX = 10000;
29+
using payload_t = std::uint32_t;
2930

3031
/*
3132
* Benchmark for removing entries.
@@ -39,11 +40,11 @@ class IndexBenchmark {
3940

4041
private:
4142
void SetupWorld(benchmark::State& state);
42-
void Insert(benchmark::State& state, PhTree<DIM, int>& tree);
43-
void Remove(benchmark::State& state, PhTree<DIM, int>& tree);
43+
void Insert(benchmark::State& state, PhTree<DIM, payload_t>& tree);
44+
void Remove(benchmark::State& state, PhTree<DIM, payload_t>& tree);
4445

4546
const TestGenerator data_type_;
46-
const int num_entities_;
47+
const size_t num_entities_;
4748

4849
std::default_random_engine random_engine_;
4950
std::uniform_int_distribution<> cube_distribution_;
@@ -66,7 +67,7 @@ template <dimension_t DIM>
6667
void IndexBenchmark<DIM>::Benchmark(benchmark::State& state) {
6768
for (auto _ : state) {
6869
state.PauseTiming();
69-
auto* tree = new PhTree<DIM, int>();
70+
auto* tree = new PhTree<DIM, payload_t>();
7071
Insert(state, *tree);
7172
state.ResumeTiming();
7273

@@ -91,16 +92,16 @@ void IndexBenchmark<DIM>::SetupWorld(benchmark::State& state) {
9192
}
9293

9394
template <dimension_t DIM>
94-
void IndexBenchmark<DIM>::Insert(benchmark::State&, PhTree<DIM, int>& tree) {
95-
for (int i = 0; i < num_entities_; ++i) {
96-
tree.emplace(points_[i], i);
95+
void IndexBenchmark<DIM>::Insert(benchmark::State&, PhTree<DIM, payload_t>& tree) {
96+
for (size_t i = 0; i < num_entities_; ++i) {
97+
tree.emplace(points_[i], (int)i);
9798
}
9899
}
99100

100101
template <dimension_t DIM>
101-
void IndexBenchmark<DIM>::Remove(benchmark::State& state, PhTree<DIM, int>& tree) {
102-
int n = 0;
103-
for (int i = 0; i < num_entities_; ++i) {
102+
void IndexBenchmark<DIM>::Remove(benchmark::State& state, PhTree<DIM, payload_t>& tree) {
103+
size_t n = 0;
104+
for (size_t i = 0; i < num_entities_; ++i) {
104105
n += tree.erase(points_[i]);
105106
}
106107

benchmark/erase_d_benchmark.cc

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ using namespace improbable::phtree::phbenchmark;
2626
namespace {
2727

2828
const int GLOBAL_MAX = 10000;
29+
using payload_t = std::uint32_t;
2930

3031
/*
3132
* Benchmark for removing entries.
@@ -39,11 +40,11 @@ class IndexBenchmark {
3940

4041
private:
4142
void SetupWorld(benchmark::State& state);
42-
void Insert(benchmark::State& state, PhTreeD<DIM, int>& tree);
43-
void Remove(benchmark::State& state, PhTreeD<DIM, int>& tree);
43+
void Insert(benchmark::State& state, PhTreeD<DIM, payload_t>& tree);
44+
void Remove(benchmark::State& state, PhTreeD<DIM, payload_t>& tree);
4445

4546
const TestGenerator data_type_;
46-
const int num_entities_;
47+
const size_t num_entities_;
4748

4849
std::default_random_engine random_engine_;
4950
std::uniform_real_distribution<> cube_distribution_;
@@ -66,7 +67,7 @@ template <dimension_t DIM>
6667
void IndexBenchmark<DIM>::Benchmark(benchmark::State& state) {
6768
for (auto _ : state) {
6869
state.PauseTiming();
69-
auto* tree = new PhTreeD<DIM, int>();
70+
auto* tree = new PhTreeD<DIM, payload_t>();
7071
Insert(state, *tree);
7172
state.ResumeTiming();
7273

@@ -91,16 +92,16 @@ void IndexBenchmark<DIM>::SetupWorld(benchmark::State& state) {
9192
}
9293

9394
template <dimension_t DIM>
94-
void IndexBenchmark<DIM>::Insert(benchmark::State&, PhTreeD<DIM, int>& tree) {
95-
for (int i = 0; i < num_entities_; ++i) {
95+
void IndexBenchmark<DIM>::Insert(benchmark::State&, PhTreeD<DIM, payload_t>& tree) {
96+
for (payload_t i = 0; i < num_entities_; ++i) {
9697
tree.emplace(points_[i], i);
9798
}
9899
}
99100

100101
template <dimension_t DIM>
101-
void IndexBenchmark<DIM>::Remove(benchmark::State& state, PhTreeD<DIM, int>& tree) {
102-
int n = 0;
103-
for (int i = 0; i < num_entities_; ++i) {
102+
void IndexBenchmark<DIM>::Remove(benchmark::State& state, PhTreeD<DIM, payload_t>& tree) {
103+
size_t n = 0;
104+
for (size_t i = 0; i < num_entities_; ++i) {
104105
n += tree.erase(points_[i]);
105106
}
106107

benchmark/extent_benchmark.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class IndexBenchmark {
4242
void QueryWorld(benchmark::State& state);
4343

4444
const TestGenerator data_type_;
45-
const int num_entities_;
45+
const size_t num_entities_;
4646

4747
PhTree<DIM, int> tree_;
4848
std::default_random_engine random_engine_;
@@ -73,8 +73,8 @@ template <dimension_t DIM>
7373
void IndexBenchmark<DIM>::SetupWorld(benchmark::State& state) {
7474
logging::info("Setting up world with {} entities and {} dimensions.", num_entities_, DIM);
7575
CreatePointData<DIM>(points_, data_type_, num_entities_, 0, GLOBAL_MAX);
76-
for (int i = 0; i < num_entities_; ++i) {
77-
tree_.emplace(points_[i], i);
76+
for (size_t i = 0; i < num_entities_; ++i) {
77+
tree_.emplace(points_[i], (int)i);
7878
}
7979

8080
state.counters["total_result_count"] = benchmark::Counter(0);

benchmark/extent_benchmark_weird.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class IndexBenchmark {
4848
void QueryWorld(benchmark::State& state);
4949

5050
const TestGenerator data_type_;
51-
const int num_entities_;
51+
const size_t num_entities_;
5252

5353
PhTree<DIM, int> tree_;
5454
std::default_random_engine random_engine_;
@@ -81,8 +81,8 @@ template <dimension_t DIM>
8181
void IndexBenchmark<DIM>::SetupWorld(benchmark::State& state) {
8282
logging::info("Setting up world with {} entities and {} dimensions.", num_entities_, DIM);
8383
CreatePointData<DIM>(points_, data_type_, num_entities_, 0, GLOBAL_MAX);
84-
for (int i = 0; i < num_entities_; ++i) {
85-
tree_.emplace(points_[i], i);
84+
for (size_t i = 0; i < num_entities_; ++i) {
85+
tree_.emplace(points_[i], (int)i);
8686
}
8787

8888
state.counters["total_result_count"] = benchmark::Counter(0);

benchmark/find_benchmark.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class IndexBenchmark {
4949
int QueryWorldFind(benchmark::State& state);
5050

5151
const TestGenerator data_type_;
52-
const int num_entities_;
52+
const size_t num_entities_;
5353
const QueryType query_type_;
5454

5555
PhTree<DIM, int> tree_;
@@ -102,8 +102,8 @@ template <dimension_t DIM>
102102
void IndexBenchmark<DIM>::SetupWorld(benchmark::State& state) {
103103
logging::info("Setting up world with {} entities and {} dimensions.", num_entities_, DIM);
104104
CreatePointData<DIM>(points_, data_type_, num_entities_, 0, GLOBAL_MAX);
105-
for (int i = 0; i < num_entities_; ++i) {
106-
tree_.emplace(points_[i], i);
105+
for (size_t i = 0; i < num_entities_; ++i) {
106+
tree_.emplace(points_[i], (int)i);
107107
}
108108

109109
state.counters["total_result_count"] = benchmark::Counter(0);

benchmark/hd_erase_d_benchmark.cc

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ using namespace improbable::phtree::phbenchmark;
2626
namespace {
2727

2828
const int GLOBAL_MAX = 10000;
29+
using payload_t = std::uint32_t;
2930

3031
/*
3132
* Benchmark for removing entries.
@@ -38,11 +39,11 @@ class IndexBenchmark {
3839

3940
private:
4041
void SetupWorld(benchmark::State& state);
41-
void Insert(benchmark::State& state, PhTreeD<DIM, int>& tree);
42-
void Remove(benchmark::State& state, PhTreeD<DIM, int>& tree);
42+
void Insert(benchmark::State& state, PhTreeD<DIM, payload_t>& tree);
43+
void Remove(benchmark::State& state, PhTreeD<DIM, payload_t>& tree);
4344

4445
const TestGenerator data_type_;
45-
const int num_entities_;
46+
const size_t num_entities_;
4647

4748
std::default_random_engine random_engine_;
4849
std::uniform_real_distribution<> cube_distribution_;
@@ -64,7 +65,7 @@ template <dimension_t DIM>
6465
void IndexBenchmark<DIM>::Benchmark(benchmark::State& state) {
6566
for (auto _ : state) {
6667
state.PauseTiming();
67-
auto* tree = new PhTreeD<DIM, int>();
68+
auto* tree = new PhTreeD<DIM, payload_t>();
6869
Insert(state, *tree);
6970
state.ResumeTiming();
7071

@@ -89,16 +90,16 @@ void IndexBenchmark<DIM>::SetupWorld(benchmark::State& state) {
8990
}
9091

9192
template <dimension_t DIM>
92-
void IndexBenchmark<DIM>::Insert(benchmark::State&, PhTreeD<DIM, int>& tree) {
93-
for (int i = 0; i < num_entities_; ++i) {
94-
tree.emplace(points_[i], i);
93+
void IndexBenchmark<DIM>::Insert(benchmark::State&, PhTreeD<DIM, payload_t>& tree) {
94+
for (size_t i = 0; i < num_entities_; ++i) {
95+
tree.emplace(points_[i], (int)i);
9596
}
9697
}
9798

9899
template <dimension_t DIM>
99-
void IndexBenchmark<DIM>::Remove(benchmark::State& state, PhTreeD<DIM, int>& tree) {
100-
int n = 0;
101-
for (int i = 0; i < num_entities_; ++i) {
100+
void IndexBenchmark<DIM>::Remove(benchmark::State& state, PhTreeD<DIM, payload_t>& tree) {
101+
size_t n = 0;
102+
for (size_t i = 0; i < num_entities_; ++i) {
102103
n += tree.erase(points_[i]);
103104
}
104105

benchmark/hd_insert_d_benchmark.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class IndexBenchmark {
4242
void Insert(benchmark::State& state, Index& tree);
4343

4444
const TestGenerator data_type_;
45-
const int num_entities_;
45+
const size_t num_entities_;
4646
std::vector<PhPointD<DIM>> points_;
4747
};
4848

@@ -84,9 +84,9 @@ void IndexBenchmark<DIM>::SetupWorld(benchmark::State& state) {
8484

8585
template <dimension_t DIM>
8686
void IndexBenchmark<DIM>::Insert(benchmark::State& state, Index& tree) {
87-
for (int i = 0; i < num_entities_; ++i) {
87+
for (size_t i = 0; i < num_entities_; ++i) {
8888
PhPointD<DIM>& p = points_[i];
89-
tree.emplace(p, i);
89+
tree.emplace(p, (int)i);
9090
}
9191

9292
state.counters["total_put_count"] += num_entities_;

0 commit comments

Comments
 (0)