Skip to content

Commit 52d9e75

Browse files
committed
Fix pedantic warnings on MSVC, GCC, and Clang
1 parent 42ab5eb commit 52d9e75

Some content is hidden

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

65 files changed

+651
-453
lines changed

examples/appearance/multiplot/colororder/colororder_2.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ int main() {
1010

1111
hold(on);
1212
for (size_t r = 1; r <= 7; ++r) {
13-
auto x = linspace(0, r, 500);
13+
auto x = linspace(0., static_cast<double>(r), 500);
1414
auto y =
1515
transform(x, [&](double x) { return sqrt(pow(r, 2) - pow(x, 2)); });
1616
plot(x, y)->line_width(15);

examples/data_distribution/binscatter/binscatter_1.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ int main() {
1515
scatter(ax1, x_reduced, y_reduced);
1616
title(ax1, "Scatter plot (n=1000)");
1717

18-
auto x = randn(1e6, 0, 1);
18+
auto x = randn(1000000, 0., 1.);
1919
auto y = transform(x, [](double x) { return 2 * x + randn(0, 1); });
2020
auto ax2 = subplot(1, 2, 1);
2121
binscatter(ax2, x, y);

examples/data_distribution/binscatter/binscatter_2.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ int main() {
1010
f->x_position(200);
1111
f->y_position(100);
1212

13-
auto x = randn(1e6, 0, 1);
13+
auto x = randn(1000000, 0., 1.);
1414
auto y = transform(x, [](double x) { return 2 * x + randn(0, 1); });
1515
std::vector x_line(x.begin(), x.begin() + 1000);
1616
std::vector y_line(y.begin(), y.begin() + 1000);

examples/data_distribution/binscatter/binscatter_3.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ int main() {
1111
f->x_position(200);
1212
f->y_position(100);
1313

14-
auto x = randn(1e6, 0, 1);
14+
auto x = randn(1000000, 0., 1.);
1515
auto y = transform(x, [](double x) { return 2 * x + randn(0, 1); });
1616

1717
bin_scatter_style b = bin_scatter_style::automatic;

examples/data_distribution/binscatter/binscatter_4.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ int main() {
1111
f->x_position(200);
1212
f->y_position(100);
1313

14-
auto x = randn(1e6, 0, 1);
14+
auto x = randn(1000000, 0., 1.);
1515
auto y = transform(x, [](double x) { return 2 * x + randn(0, 1); });
1616

1717
bin_scatter_style b = bin_scatter_style::heatmap;

examples/data_distribution/binscatter/binscatter_5.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ int main() {
1212
f->y_position(100);
1313
f->quiet_mode(true);
1414

15-
auto x = randn(1e4, 0, 1);
16-
auto y = randn(1e4, 0, 1);
15+
auto x = randn(10000, 0., 1.);
16+
auto y = randn(10000, 0., 1.);
1717

1818
subplot(2, 3, 0);
1919
scatter(x, y);

examples/data_distribution/binscatter/binscatter_6.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
int main() {
66
using namespace matplot;
77

8-
auto x = randn(1e5, 0, 1);
9-
auto y = randn(1e5, 0, 1);
8+
auto x = randn(100000, 0., 1.);
9+
auto y = randn(100000, 0., 1.);
1010

1111
binscatter(x, y, bin_scatter_style::point_colormap);
1212
colormap(gca(), palette::parula());

examples/data_distribution/binscatter/binscatter_7.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
int main() {
66
using namespace matplot;
77

8-
auto x = randn(100000, 0, 1);
9-
auto y = randn(100000, 0, 1);
8+
auto x = randn(100000, 0., 1.);
9+
auto y = randn(100000, 0., 1.);
1010

1111
binscatter(x, y, 20, 30, bin_scatter_style::heatmap);
1212
axis(tight);

examples/data_distribution/heatmap/heatmap_5.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ int main() {
1818
"Severe Storm", "Thunder Storm", "Unknown", "Wind", "Winter Storm"});
1919
xlabel(ax, "Region");
2020
ylabel(ax, "Cause");
21-
double w = ax->width();
22-
ax->width(w * 0.85);
23-
ax->x_origin(ax->x_origin() + w * 0.1);
21+
float w = ax->width();
22+
ax->width(w * 0.85f);
23+
ax->x_origin(ax->x_origin() + w * 0.1f);
2424

2525
show();
2626
return 0;

examples/data_distribution/heatmap/heatmap_6.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ int main() {
2020
"Severe Storm", "Thunder Storm", "Unknown", "Wind", "Winter Storm"});
2121
xlabel(ax, "Region");
2222
ylabel(ax, "Cause");
23-
double w = ax->width();
24-
ax->width(w * 0.85);
25-
ax->x_origin(ax->x_origin() + w * 0.1);
23+
float w = ax->width();
24+
ax->width(w * 0.85f);
25+
ax->x_origin(ax->x_origin() + w * 0.1f);
2626

2727
show();
2828
return 0;

examples/data_distribution/heatmap/heatmap_7.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ int main() {
2020
"Severe Storm", "Thunder Storm", "Unknown", "Wind", "Winter Storm"});
2121
xlabel(ax, "Region");
2222
ylabel(ax, "Cause");
23-
double w = ax->width();
24-
ax->width(w * 0.85);
25-
ax->x_origin(ax->x_origin() + w * 0.1);
23+
float w = ax->width();
24+
ax->width(w * 0.85f);
25+
ax->x_origin(ax->x_origin() + w * 0.1f);
2626

2727
show();
2828
return 0;

examples/geography/geoplot/geoplot_3.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ int main() {
88
auto [lon_star, lat_star] = greedy_tsp(lon, lat);
99
geoplot(lat_star, lon_star)
1010
->marker("o")
11-
.marker_colors(iota(1, names.size()));
11+
.marker_colors(iota(1., static_cast<double>(names.size())));
1212
text(lon, lat, names);
1313

1414
show();

examples/geography/geoplot/geoplot_6.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void eurotrip_solver::draw() {
121121

122122
vector<double> sorted_lat;
123123
vector<double> sorted_lon;
124-
for (const int &idx : best_tour_) {
124+
for (const size_t &idx : best_tour_) {
125125
sorted_lat.emplace_back(lat_[idx]);
126126
sorted_lon.emplace_back(lon_[idx]);
127127
}

examples/geography/geoplot/geoplot_7.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ double americas_trip_solver::tour_distance(const vector<size_t> &tour) {
122122
void americas_trip_solver::draw() {
123123
vector<double> sorted_lat;
124124
vector<double> sorted_lon;
125-
for (const int &idx : best_tour_) {
125+
for (const size_t &idx : best_tour_) {
126126
sorted_lat.emplace_back(lat_[idx]);
127127
sorted_lon.emplace_back(lon_[idx]);
128128
}

examples/graphs/graph/graph_5.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ int main() {
99
auto g = graph(edges);
1010
g->layout_algorithm(network::layout::force);
1111

12-
for (size_t i = 0; i < 300; ++i) {
12+
for (int i = 0; i < 300; ++i) {
1313
g->layout_iterations(i);
1414
std::this_thread::sleep_for(std::chrono::milliseconds(100));
1515
}

examples/line_plot/errorbar/errorbar_1.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ int main() {
66

77
std::vector<double> x = iota(0, 10, 100);
88
std::vector<double> y = {20, 30, 45, 40, 60, 65, 80, 75, 95, 90};
9-
std::vector<double> err(10, y.size());
9+
std::vector<double> err(y.size(), 10.);
1010
errorbar(x, y, err);
1111
axis({0, 100, 0, 110});
1212
show();

examples/line_plot/errorbar/errorbar_2.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ int main() {
66

77
std::vector<double> x = iota(0, 10, 100);
88
std::vector<double> y = {20, 30, 45, 40, 60, 65, 80, 75, 95, 90};
9-
std::vector<double> err(10, y.size());
9+
std::vector<double> err(y.size(), 10.);
1010
errorbar(x, y, err)->filled_curve(true);
1111

1212
axis({0, 100, 0, 110});

source/3rd_party/CMakeLists.txt

+8-4
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,20 @@ else()
1717
${CMAKE_CURRENT_SOURCE_DIR}/nodesoup/src/layout.cpp
1818
${CMAKE_CURRENT_SOURCE_DIR}/nodesoup/src/layout.hpp
1919
${CMAKE_CURRENT_SOURCE_DIR}/nodesoup/src/nodesoup.cpp
20-
${CMAKE_CURRENT_SOURCE_DIR}/nodesoup/include/nodesoup.hpp
21-
)
20+
${CMAKE_CURRENT_SOURCE_DIR}/nodesoup/include/nodesoup.hpp
21+
)
2222
set_target_properties(nodesoup PROPERTIES
23-
CXX_VISIBILITY_PRESET "hidden")
23+
CXX_VISIBILITY_PRESET "hidden")
2424
target_include_directories(nodesoup
25-
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/nodesoup/include>)
25+
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/nodesoup/include>)
2626

2727
# Hackfix to support MSVC standard library
2828
# https://docs.microsoft.com/en-us/cpp/c-runtime-library/math-constants?view=vs-2019
2929
target_compile_definitions(nodesoup PRIVATE _USE_MATH_DEFINES)
30+
31+
if (${BUILD_SHARED_LIBS})
32+
set_target_properties(nodesoup PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
33+
endif ()
3034
endif()
3135

3236
# Install (only necessary for static lib build)

source/matplot/CMakeLists.txt

+25-9
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ if (BUILD_WITH_PEDANTIC_WARNINGS)
136136
target_compile_options(matplot PRIVATE /W4 /WX)
137137
else ()
138138
target_compile_options(matplot PRIVATE -Wall -Wextra -pedantic -Werror)
139+
# Allow the warnings related to the bundled CImg
140+
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
141+
target_compile_options(matplot PRIVATE -Wno-null-pointer-arithmetic -Wno-char-subscripts)
142+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
143+
target_compile_options(matplot PRIVATE -Wno-error=class-memaccess -Wno-class-memaccess)
144+
endif ()
139145
endif ()
140146
endif ()
141147

@@ -173,25 +179,35 @@ if (BUILD_EXPERIMENTAL_OPENGL_BACKEND)
173179

174180
# https://github.com/Dav1dde/glad
175181
find_package(GLAD QUIET)
176-
if (GLAD_FOUND)
177-
add_library(glad INTERFACE)
178-
target_include_directories(glad INTERFACE ${GLAD_INCLUDE_PATH})
179-
target_link_libraries(glad INTERFACE ${GLAD_LIBRARIES})
180-
else()
181-
# Only if not found, to avoid ODR violations
182+
if (NOT GLAD_FOUND AND NOT TARGET glad)
183+
# Use CPM only if not found, to avoid ODR violations
182184
# find_package(GLAD REQUIRE) would suffice if it worked well
183185
CPMAddPackage(NAME glad GIT_REPOSITORY https://github.com/Dav1dde/glad GIT_TAG df8e9e16110b305479a875399cee13daa0ccadd9 VERSION 0.1.33)
184-
endif()
186+
else ()
187+
# FindGLAD does not usually create a target, so we create an interface target
188+
if (NOT TARGET glad)
189+
add_library(glad INTERFACE)
190+
target_include_directories(glad INTERFACE ${GLAD_INCLUDE_PATH})
191+
target_link_libraries(glad INTERFACE ${GLAD_LIBRARIES})
192+
endif ()
193+
endif ()
185194

195+
# https://github.com/glfw/glfw
186196
find_package(glfw3 REQUIRED)
197+
if (NOT GLFW3_FOUND AND NOT TARGET glfw)
198+
# Use CPM only if not found, to avoid ODR violations
199+
# find_package(glfw3 REQUIRE) would suffice if it worked well
200+
CPMAddPackage(NAME glfw3 GIT_REPOSITORY https://github.com/glfw/glfw VERSION 3.3.2 GIT_TAG 3.3.2 OPTIONS "GLFW_BUILD_DOCS OFF" "GLFW_BUILD_EXAMPLES OFF" "GLFW_BUILD_TESTS OFF" "GLFW_INSTALL OFF")
201+
endif ()
187202

188203
add_library(matplot_opengl
189204
backend/opengl_embed.h
190205
backend/opengl_embed.cpp
191206
backend/opengl.h
192-
backend/opengl.cpp)
207+
backend/opengl.cpp
208+
)
193209
target_include_directories(matplot_opengl PUBLIC matplot)
194-
target_link_libraries(matplot_opengl PUBLIC matplot glad glfw)
210+
target_link_libraries(matplot_opengl PUBLIC matplot glad glfw ${CMAKE_DL_LIBS})
195211
endif()
196212

197213

source/matplot/axes_objects/bars.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ namespace matplot {
2222
if (parent_->children().empty()) {
2323
parent_->x_axis().limits({0, double(ys_[0].size() + 1)});
2424
if (ys_[0].size() <= 15) {
25-
parent_->x_axis().tick_values(iota(1, ys_[0].size()));
25+
parent_->x_axis().tick_values(
26+
iota(1., static_cast<double>(ys_[0].size())));
2627
}
2728
}
2829
if (parent_->y_axis().limits_mode_auto()) {
@@ -122,7 +123,7 @@ namespace matplot {
122123
}
123124

124125
double bars::range_for_cluster() {
125-
double min_x_diff = x_minimum_difference();
126+
// double min_x_diff = x_minimum_difference();
126127
const size_t n_bar_groups = ys_.size();
127128
// space taken by the cluster in the x axis
128129
return bar_width_ / n_bar_groups;
@@ -161,15 +162,15 @@ namespace matplot {
161162
if (!x_.empty()) {
162163
return *std::max_element(x_.begin(), x_.end());
163164
} else {
164-
return ys_[0].size() + 1;
165+
return static_cast<double>(ys_[0].size() + 1);
165166
}
166167
}
167168

168169
double bars::xmin() {
169170
if (!x_.empty()) {
170171
return *std::min_element(x_.begin(), x_.end());
171172
} else {
172-
return ys_[0].size() + 1;
173+
return static_cast<double>(ys_[0].size() + 1);
173174
}
174175
}
175176

source/matplot/axes_objects/bars.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ namespace matplot {
3232
/// If we receive an axes_handle, we can convert it to a raw
3333
/// pointer because there is no ownership involved here
3434
template <class... Args>
35-
bars(const axes_handle &parent, Args&&... args)
35+
bars(const axes_handle &parent, Args &&... args)
3636
: bars(parent.get(), std::forward<Args>(args)...) {}
3737

38+
virtual ~bars() = default;
39+
3840
public /* xlim object virtual functions */:
3941
// std::string set_variables_string() override;
4042
std::string plot_string() override;

source/matplot/axes_objects/box_chart.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ namespace matplot {
8888
face_color_ = parent_->get_color_and_bump();
8989
edge_color_ = face_color_;
9090
manual_face_color_ = true;
91-
face_color_[0] = 0.6 + 0.4 * face_color_[0];
91+
face_color_[0] = 0.6f + 0.4f * face_color_[0];
9292
edge_color_[0] /= 2.;
9393
edge_color_[1] /= 2.;
9494
edge_color_[2] /= 2.;

source/matplot/axes_objects/box_chart.h

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ namespace matplot {
4545
box_chart(const axes_handle &parent, Args&&... args)
4646
: box_chart(parent.get(), std::forward<Args>(args)...) {}
4747

48+
virtual ~box_chart() = default;
4849
public /* xlim object virtual functions */:
4950
std::string set_variables_string() override;
5051
std::string plot_string() override;

source/matplot/axes_objects/circles.h

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace matplot {
3131
circles(const axes_handle &parent, Args&&... args)
3232
: circles(parent.get(), std::forward<Args>(args)...) {}
3333

34+
virtual ~circles() = default;
3435
public /* mandatory virtual functions */:
3536
// std::string set_variables_string() override;
3637
std::string plot_string() override;

0 commit comments

Comments
 (0)