From 9c17dfcaca44f23e82ede2ba9bb22891b12e43a3 Mon Sep 17 00:00:00 2001 From: MikeG Date: Thu, 4 Jan 2024 11:41:29 +0100 Subject: [PATCH] work w/ clang17 (#486) Disable`-Wno-float-equal` after a couple fixes --- CMake/CompilerFlags.cmake | 1 - binds/python/morphio.cpp | 13 ++++++++++--- include/morphio/section_base.h | 3 +-- src/mut/writer_swc.cpp | 3 ++- src/vasc/section.cpp | 4 ++-- tests/test_point_utils.cpp | 5 +++-- tests/test_utilities.cpp | 2 +- 7 files changed, 19 insertions(+), 12 deletions(-) diff --git a/CMake/CompilerFlags.cmake b/CMake/CompilerFlags.cmake index 8e2590288..ed6e45c9e 100644 --- a/CMake/CompilerFlags.cmake +++ b/CMake/CompilerFlags.cmake @@ -27,7 +27,6 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(FLAGS "${FLAGS} -Wno-documentation") set(FLAGS "${FLAGS} -Wno-documentation-unknown-command") - set(FLAGS "${FLAGS} -Wno-float-equal") set(FLAGS "${FLAGS} -Wno-padded") set(FLAGS "${FLAGS} -Wno-weak-vtables") set(FLAGS "${FLAGS} -Wno-covered-switch-default") diff --git a/binds/python/morphio.cpp b/binds/python/morphio.cpp index 2fe4e85d5..570b0f0d1 100644 --- a/binds/python/morphio.cpp +++ b/binds/python/morphio.cpp @@ -10,11 +10,14 @@ #include "bind_mutable.h" #include "bind_vasculature.h" -#include "bindings_utils.h" - - namespace py = pybind11; +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-warning-option" +#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" +#endif + PYBIND11_MODULE(_morphio, m) { bind_enums(m); bind_misc(m); @@ -27,3 +30,7 @@ PYBIND11_MODULE(_morphio, m) { py::module vasc_module = m.def_submodule("vasculature"); bind_vasculature(vasc_module); } + +#if defined(__clang__) +#pragma clang diagnostic pop +#endif diff --git a/include/morphio/section_base.h b/include/morphio/section_base.h index 465cc7583..f829a08ce 100644 --- a/include/morphio/section_base.h +++ b/include/morphio/section_base.h @@ -101,8 +101,7 @@ range SectionBase::get() const { return {}; } - auto ptr_start = data.data() + range_.first; - return {ptr_start, range_.second - range_.first}; + return {&data.at(range_.first), range_.second - range_.first}; } template diff --git a/src/mut/writer_swc.cpp b/src/mut/writer_swc.cpp index e9a7850a4..846e9ff9a 100644 --- a/src/mut/writer_swc.cpp +++ b/src/mut/writer_swc.cpp @@ -94,7 +94,8 @@ int writeSoma(std::ofstream& myfile, const std::shared_ptr& /* Only skip duplicate if it has the same diameter */ bool _skipDuplicate(const std::shared_ptr& section) { - return section->diameters().front() == section->parent()->diameters().back(); + return std::fabs(section->diameters().front() - section->parent()->diameters().back()) < + morphio::epsilon; } void validateSWCSoma(const morphio::mut::Morphology& morph) { diff --git a/src/vasc/section.cpp b/src/vasc/section.cpp index 9f56b9ed7..df7517c52 100644 --- a/src/vasc/section.cpp +++ b/src/vasc/section.cpp @@ -62,8 +62,8 @@ range Section::get() const { if (data.empty()) { return range(); } - auto ptr_start = data.data() + range_.first; - return range(ptr_start, range_.second - range_.first); + return range(&data.at(range_.first), + range_.second - range_.first); } std::vector
Section::predecessors() const { diff --git a/tests/test_point_utils.cpp b/tests/test_point_utils.cpp index bc635631a..5d355633c 100644 --- a/tests/test_point_utils.cpp +++ b/tests/test_point_utils.cpp @@ -11,10 +11,11 @@ TEST_CASE("morphio::Point") { using namespace morphio; Point p{10., 10., 10.}; + std::vector points = {p, p, p}; CHECK(subtract(p, p) == morphio::Point{0, 0, 0}); - CHECK(euclidean_distance(p, p) == 0); + REQUIRE_THAT(euclidean_distance(p, p), Catch::WithinAbs(0, 0.001)); CHECK(dumpPoint(p) == "10 10 10"); CHECK(dumpPoints(points) == "10 10 10\n10 10 10\n10 10 10\n"); @@ -34,7 +35,7 @@ TEST_CASE("morphio::Point") { auto r = morphio::range(); std::stringstream ss; ss << r; - CHECK(ss.str() == ""); + CHECK(ss.str().empty()); ss.clear(); diff --git a/tests/test_utilities.cpp b/tests/test_utilities.cpp index ef3cc164e..cca04f7e3 100644 --- a/tests/test_utilities.cpp +++ b/tests/test_utilities.cpp @@ -125,7 +125,7 @@ TEST_CASE("morphio::shared_utils") { const std::vector points = {{0, 0, 0}}; const std::vector diameters = {1}; CHECK(centerOfGravity(points) == points[0]); - CHECK(maxDistanceToCenterOfGravity(points) == 0); + CHECK(maxDistanceToCenterOfGravity(points) == Approx(0)); CHECK(_somaSurface(SOMA_SINGLE_POINT, diameters, points) == Approx(morphio::PI)); CHECK(_somaSurface(SOMA_SINGLE_POINT, diameters, points) == Approx(morphio::PI)); }