diff --git a/include/mapbox/feature.hpp b/include/mapbox/feature.hpp index 68b23f8..832216a 100644 --- a/include/mapbox/feature.hpp +++ b/include/mapbox/feature.hpp @@ -10,6 +10,7 @@ #include #include +#include "mapbox/geometry/warning.hpp" namespace mapbox { namespace feature { @@ -17,14 +18,14 @@ namespace feature { struct equal_comp_shared_ptr { -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wfloat-equal" + MAPBOX_GEOMETRY_DISABLE_WARNING_PUSH + MAPBOX_GEOMETRY_DISABLE_WARNING_FLOAT_EQUAL template bool operator()(T const& lhs, T const& rhs) const { return lhs == rhs; } -#pragma GCC diagnostic pop + MAPBOX_GEOMETRY_DISABLE_WARNING_POP template bool operator()(std::shared_ptr const& lhs, std::shared_ptr const& rhs) const diff --git a/include/mapbox/geometry/point.hpp b/include/mapbox/geometry/point.hpp index da8d677..d78253c 100644 --- a/include/mapbox/geometry/point.hpp +++ b/include/mapbox/geometry/point.hpp @@ -1,5 +1,7 @@ #pragma once +#include "warning.hpp" + namespace mapbox { namespace geometry { @@ -21,8 +23,8 @@ struct point T y; }; -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wfloat-equal" +MAPBOX_GEOMETRY_DISABLE_WARNING_PUSH +MAPBOX_GEOMETRY_DISABLE_WARNING_FLOAT_EQUAL template constexpr bool operator==(point const& lhs, point const& rhs) @@ -30,7 +32,7 @@ constexpr bool operator==(point const& lhs, point const& rhs) return lhs.x == rhs.x && lhs.y == rhs.y; } -#pragma GCC diagnostic pop +MAPBOX_GEOMETRY_DISABLE_WARNING_POP template constexpr bool operator!=(point const& lhs, point const& rhs) diff --git a/include/mapbox/geometry/warning.hpp b/include/mapbox/geometry/warning.hpp new file mode 100644 index 0000000..f36a086 --- /dev/null +++ b/include/mapbox/geometry/warning.hpp @@ -0,0 +1,31 @@ +#ifndef GEOMETRY_WARNING_HPP +#define GEOMETRY_WARNING_HPP + +#if defined(_MSC_VER) +#define MAPBOX_GEOMETRY_DISABLE_WARNING_PUSH __pragma(warning(push)) +#define MAPBOX_GEOMETRY_DISABLE_WARNING_POP __pragma(warning(pop)) +#define MAPBOX_GEOMETRY_DISABLE_WARNING(warningNumber) __pragma(warning(disable \ + : warningNumber)) + +// add warnings to deactivate here +// example: #define DISABLE_WARNING_UNREFERENCED_FORMAL_PARAMETER MAPBOX_GEOMETRY_DISABLE_WARNING(4100) +#define MAPBOX_GEOMETRY_DISABLE_WARNING_FLOAT_EQUAL //MAPBOX_GEOMETRY_DISABLE_WARNING(??) + +#elif defined(__GNUC__) || defined(__clang__) +#define MAPBOX_GEOMETRY_DO_PRAGMA(X) _Pragma(#X) +#define MAPBOX_GEOMETRY_DISABLE_WARNING_PUSH MAPBOX_GEOMETRY_DO_PRAGMA(GCC diagnostic push) +#define MAPBOX_GEOMETRY_DISABLE_WARNING_POP MAPBOX_GEOMETRY_DO_PRAGMA(GCC diagnostic pop) +#define MAPBOX_GEOMETRY_DISABLE_WARNING(warningName) MAPBOX_GEOMETRY_DO_PRAGMA(GCC diagnostic ignored #warningName) +// add warnings to deactivate here +// example: #define DISABLE_WARNING_UNREFERENCED_FORMAL_PARAMETER MAPBOX_GEOMETRY_DISABLE_WARNING(-Wunused-parameter) +// disable clang-format for the next line since the waring definition would be formatted. +// clang-format off +#define MAPBOX_GEOMETRY_DISABLE_WARNING_FLOAT_EQUAL MAPBOX_GEOMETRY_DISABLE_WARNING(-Wfloat-equal) +// clang-format on +#else +#define MAPBOX_GEOMETRY_DISABLE_WARNING_PUSH +#define MAPBOX_GEOMETRY_DISABLE_WARNING_POP +// add all of the above warnings here (will be used if unknown compiler) +#define MAPBOX_GEOMETRY_DISABLE_WARNING_FLOAT_EQUAL +#endif +#endif