From 635ff4ef2d757412f223886288a91077de48c4c0 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 18 Sep 2018 22:35:28 +0200 Subject: [PATCH] Added GLM_FORCE_SILENT_WARNINGS to silent GLM warnings when using language extensions but using W4 or Wpedantic warnings #814 #775 --- glm/detail/setup.hpp | 15 ++++++++ glm/detail/type_quat.hpp | 24 ++++++++++++ glm/detail/type_vec1.hpp | 24 ++++++++++++ glm/detail/type_vec2.hpp | 24 ++++++++++++ glm/detail/type_vec3.hpp | 24 ++++++++++++ glm/detail/type_vec4.hpp | 24 ++++++++++++ glm/ext/vector_relational.inl | 16 ++++---- manual.md | 6 +++ readme.md | 3 +- test/ext/ext_scalar_relational.cpp | 16 +++----- test/ext/ext_vector_relational.cpp | 61 ++++++++++++++++++++++++++++++ 11 files changed, 219 insertions(+), 18 deletions(-) diff --git a/glm/detail/setup.hpp b/glm/detail/setup.hpp index ff02ec54..a26c2dea 100644 --- a/glm/detail/setup.hpp +++ b/glm/detail/setup.hpp @@ -764,6 +764,15 @@ namespace detail # define GLM_CONFIG_ANONYMOUS_STRUCT GLM_DISABLE #endif +/////////////////////////////////////////////////////////////////////////////////// +// Silent warnings + +#ifdef GLM_FORCE_SILENT_WARNINGS +# define GLM_SILENT_WARNINGS GLM_ENABLE +#else +# define GLM_SILENT_WARNINGS GLM_DISABLE +#endif + /////////////////////////////////////////////////////////////////////////////////// // Precision @@ -1003,6 +1012,12 @@ namespace detail # pragma message("GLM: GLM_FORCE_UNRESTRICTED_GENTYPE is undefined. Follows strictly GLSL on valid function genTypes.") # endif +# if GLM_SILENT_WARNINGS == GLM_ENABLE +# pragma message("GLM: GLM_FORCE_SILENT_WARNINGS is defined. Ignores C++ warnings from using C++ language extensions.") +# else +# pragma message("GLM: GLM_FORCE_SILENT_WARNINGS is undefined. Shows C++ warnings from using C++ language extensions.") +# endif + # ifdef GLM_FORCE_SINGLE_ONLY # pragma message("GLM: GLM_FORCE_SINGLE_ONLY is defined. Using only single precision floating-point types") # endif diff --git a/glm/detail/type_quat.hpp b/glm/detail/type_quat.hpp index 5b6f7872..b49c2534 100644 --- a/glm/detail/type_quat.hpp +++ b/glm/detail/type_quat.hpp @@ -38,6 +38,20 @@ namespace glm // -- Data -- +# if GLM_SILENT_WARNINGS == GLM_ENABLE +# if GLM_COMPILER & GLM_COMPILER_GCC +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wpedantic" +# elif GLM_COMPILER & GLM_COMPILER_CLANG +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wgnu-anonymous-struct" +# pragma clang diagnostic ignored "-Wnested-anon-types" +# elif GLM_COMPILER & GLM_COMPILER_VC +# pragma warning(push) +# pragma warning(disable: 4201) // nonstandard extension used : nameless struct/union +# endif +# endif + # if GLM_LANG & GLM_LANG_CXXMS_FLAG union { @@ -49,6 +63,16 @@ namespace glm T x, y, z, w; # endif +# if GLM_SILENT_WARNINGS == GLM_ENABLE +# if GLM_COMPILER & GLM_COMPILER_CLANG +# pragma clang diagnostic pop +# elif GLM_COMPILER & GLM_COMPILER_GCC +# pragma GCC diagnostic pop +# elif GLM_COMPILER & GLM_COMPILER_VC +# pragma warning(pop) +# endif +# endif + // -- Component accesses -- typedef length_t length_type; diff --git a/glm/detail/type_vec1.hpp b/glm/detail/type_vec1.hpp index 5c0797aa..51163f14 100644 --- a/glm/detail/type_vec1.hpp +++ b/glm/detail/type_vec1.hpp @@ -24,6 +24,20 @@ namespace glm // -- Data -- +# if GLM_SILENT_WARNINGS == GLM_ENABLE +# if GLM_COMPILER & GLM_COMPILER_GCC +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wpedantic" +# elif GLM_COMPILER & GLM_COMPILER_CLANG +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wgnu-anonymous-struct" +# pragma clang diagnostic ignored "-Wnested-anon-types" +# elif GLM_COMPILER & GLM_COMPILER_VC +# pragma warning(push) +# pragma warning(disable: 4201) // nonstandard extension used : nameless struct/union +# endif +# endif + # if GLM_CONFIG_XYZW_ONLY T x; # elif GLM_CONFIG_ANONYMOUS_STRUCT == GLM_ENABLE @@ -55,6 +69,16 @@ namespace glm GLM_SWIZZLE_GEN_VEC_FROM_VEC1(T, Q) # endif */ +# endif + +# if GLM_SILENT_WARNINGS == GLM_ENABLE +# if GLM_COMPILER & GLM_COMPILER_CLANG +# pragma clang diagnostic pop +# elif GLM_COMPILER & GLM_COMPILER_GCC +# pragma GCC diagnostic pop +# elif GLM_COMPILER & GLM_COMPILER_VC +# pragma warning(pop) +# endif # endif // -- Component accesses -- diff --git a/glm/detail/type_vec2.hpp b/glm/detail/type_vec2.hpp index 81a6815e..52ef408e 100644 --- a/glm/detail/type_vec2.hpp +++ b/glm/detail/type_vec2.hpp @@ -24,6 +24,20 @@ namespace glm // -- Data -- +# if GLM_SILENT_WARNINGS == GLM_ENABLE +# if GLM_COMPILER & GLM_COMPILER_GCC +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wpedantic" +# elif GLM_COMPILER & GLM_COMPILER_CLANG +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wgnu-anonymous-struct" +# pragma clang diagnostic ignored "-Wnested-anon-types" +# elif GLM_COMPILER & GLM_COMPILER_VC +# pragma warning(push) +# pragma warning(disable: 4201) // nonstandard extension used : nameless struct/union +# endif +# endif + # if GLM_CONFIG_XYZW_ONLY T x, y; # elif GLM_CONFIG_ANONYMOUS_STRUCT == GLM_ENABLE @@ -54,6 +68,16 @@ namespace glm # if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION GLM_SWIZZLE_GEN_VEC_FROM_VEC2(T, Q) # endif//GLM_CONFIG_SWIZZLE +# endif + +# if GLM_SILENT_WARNINGS == GLM_ENABLE +# if GLM_COMPILER & GLM_COMPILER_CLANG +# pragma clang diagnostic pop +# elif GLM_COMPILER & GLM_COMPILER_GCC +# pragma GCC diagnostic pop +# elif GLM_COMPILER & GLM_COMPILER_VC +# pragma warning(pop) +# endif # endif // -- Component accesses -- diff --git a/glm/detail/type_vec3.hpp b/glm/detail/type_vec3.hpp index e7bf867f..a7962309 100644 --- a/glm/detail/type_vec3.hpp +++ b/glm/detail/type_vec3.hpp @@ -24,6 +24,20 @@ namespace glm // -- Data -- +# if GLM_SILENT_WARNINGS == GLM_ENABLE +# if GLM_COMPILER & GLM_COMPILER_GCC +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wpedantic" +# elif GLM_COMPILER & GLM_COMPILER_CLANG +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wgnu-anonymous-struct" +# pragma clang diagnostic ignored "-Wnested-anon-types" +# elif GLM_COMPILER & GLM_COMPILER_VC +# pragma warning(push) +# pragma warning(disable: 4201) // nonstandard extension used : nameless struct/union +# endif +# endif + # if GLM_CONFIG_XYZW_ONLY T x, y, z; # elif GLM_CONFIG_ANONYMOUS_STRUCT == GLM_ENABLE @@ -57,6 +71,16 @@ namespace glm # endif//GLM_CONFIG_SWIZZLE # endif//GLM_LANG +# if GLM_SILENT_WARNINGS == GLM_ENABLE +# if GLM_COMPILER & GLM_COMPILER_CLANG +# pragma clang diagnostic pop +# elif GLM_COMPILER & GLM_COMPILER_GCC +# pragma GCC diagnostic pop +# elif GLM_COMPILER & GLM_COMPILER_VC +# pragma warning(pop) +# endif +# endif + // -- Component accesses -- /// Return the count of components of the vector diff --git a/glm/detail/type_vec4.hpp b/glm/detail/type_vec4.hpp index 0de476c2..15fabe12 100644 --- a/glm/detail/type_vec4.hpp +++ b/glm/detail/type_vec4.hpp @@ -24,6 +24,20 @@ namespace glm // -- Data -- +# if GLM_SILENT_WARNINGS == GLM_ENABLE +# if GLM_COMPILER & GLM_COMPILER_GCC +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wpedantic" +# elif GLM_COMPILER & GLM_COMPILER_CLANG +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wgnu-anonymous-struct" +# pragma clang diagnostic ignored "-Wnested-anon-types" +# elif GLM_COMPILER & GLM_COMPILER_VC +# pragma warning(push) +# pragma warning(disable: 4201) // nonstandard extension used : nameless struct/union +# endif +# endif + # if GLM_CONFIG_XYZW_ONLY T x, y, z, w; # elif GLM_CONFIG_ANONYMOUS_STRUCT == GLM_ENABLE @@ -56,6 +70,16 @@ namespace glm # if GLM_CONFIG_SWIZZLE == GLM_SWIZZLE_FUNCTION GLM_SWIZZLE_GEN_VEC_FROM_VEC4(T, Q) # endif +# endif + +# if GLM_SILENT_WARNINGS == GLM_ENABLE +# if GLM_COMPILER & GLM_COMPILER_CLANG +# pragma clang diagnostic pop +# elif GLM_COMPILER & GLM_COMPILER_GCC +# pragma GCC diagnostic pop +# elif GLM_COMPILER & GLM_COMPILER_VC +# pragma warning(pop) +# endif # endif // -- Component accesses -- diff --git a/glm/ext/vector_relational.inl b/glm/ext/vector_relational.inl index 98778c66..c48d6d27 100644 --- a/glm/ext/vector_relational.inl +++ b/glm/ext/vector_relational.inl @@ -49,12 +49,14 @@ namespace glm if(a.negative() != b.negative()) { // Check for equality to make sure +0==-0 - return a.mantissa() == b.mantissa() && a.exponent() == b.exponent(); + Result[i] = a.mantissa() == b.mantissa() && a.exponent() == b.exponent(); + } + else + { + // Find the difference in ULPs. + typename detail::float_t::int_type const DiffULPs = abs(a.i - b.i); + Result[i] = DiffULPs <= MaxULPs[i]; } - - // Find the difference in ULPs. - typename detail::float_t::int_type const DiffULPs = abs(a.i - b.i); - Result[i] = DiffULPs <= MaxULPs; } return Result; } @@ -62,12 +64,12 @@ namespace glm template GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec notEqual(vec const& x, vec const& y, int MaxULPs) { - return !equal(x, y, MaxULPs); + return notEqual(x, y, vec(MaxULPs)); } template GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec notEqual(vec const& x, vec const& y, vec const& MaxULPs) { - return !equal(x, y, MaxULPs); + return not_(equal(x, y, MaxULPs)); } }//namespace glm diff --git a/manual.md b/manual.md index 03de5b3b..e4b34f16 100644 --- a/manual.md +++ b/manual.md @@ -33,6 +33,7 @@ + [2.16. GLM\_FORCE\_DEPTH\_ZERO\_TO\_ONE: Force the use of a clip space between 0 to 1](#section2_16) + [2.17. GLM\_FORCE\_SIZE\_T\_LENGTH: Vector and matrix static size type](#section2_17) + [2.18. GLM\_FORCE\_UNRESTRICTED\_GENTYPE: Removing genType restriction](#section2_18) ++ [2.19. GLM\_FORCE\_SILENT\_WARNINGS: Silent C++ warnings from language extensions](#section2_19) + [3. Stable extensions](#section3) + [3.1. Scalar types](#section3_1) + [3.2. Scalar functions](#section3_2) @@ -696,6 +697,11 @@ int average(int const A, int const B) } ``` +### 2.19. GLM\_FORCE\_SILENT\_WARNINGS: Silent C++ warnings from language extensions + +When using /W4 on Visual C++ or -Wpedantic on GCC, for example, the compilers will generate warnings for using C++ language extensions (/Za with Visual C++) such as anonymous struct. +GLM relies on anonymous structs for swizzle operators and aligned vector types. To silent those warnings define `GLM_FORCE_SILENT_WARNINGS` before including GLM headers. + ---
diff --git a/readme.md b/readme.md index 9a961761..913bdf58 100644 --- a/readme.md +++ b/readme.md @@ -52,9 +52,10 @@ glm::mat4 camera(float Translate, glm::vec2 const& Rotate) ## Release notes -### [GLM 0.9.9.3](https://github.com/g-truc/glm/commits/master) - 201X-XX-XX +### [GLM 0.9.9.3](https://github.com/g-truc/glm/commits/master) - 2018-XX-XX #### Features: - Added equal and notEqual overload with max ULPs parameters for scalar numbers #121 +- Added GLM_FORCE_SILENT_WARNINGS to silent GLM warnings when using language extensions but using W4 or Wpedantic warnings #814 #775 ### [GLM 0.9.9.2](https://github.com/g-truc/glm/releases/tag/0.9.9.2) - 2018-09-14 #### Fixes: diff --git a/test/ext/ext_scalar_relational.cpp b/test/ext/ext_scalar_relational.cpp index b1bfd343..53b4c9ee 100644 --- a/test/ext/ext_scalar_relational.cpp +++ b/test/ext/ext_scalar_relational.cpp @@ -1,7 +1,7 @@ #include #include -int test_equal_epsilon() +static int test_equal_epsilon() { # if GLM_CONFIG_CONSTEXP == GLM_ENABLE static_assert(glm::equal(1.01f, 1.02f, 0.1f), "GLM: Failed constexpr"); @@ -16,7 +16,7 @@ int test_equal_epsilon() return Error; } -int test_notEqual_epsilon() +static int test_notEqual_epsilon() { # if GLM_CONFIG_CONSTEXP == GLM_ENABLE static_assert(glm::notEqual(1.01f, 1.02f, 0.001f), "GLM: Failed constexpr"); @@ -31,8 +31,7 @@ int test_notEqual_epsilon() return Error; } -#if GLM_LANG & GLM_LANG_CXX11_FLAG -int test_equal_ulps() +static int test_equal_ulps() { int Error = 0; @@ -51,7 +50,7 @@ int test_equal_ulps() return Error; } -int test_notEqual_ulps() +static int test_notEqual_ulps() { int Error = 0; @@ -69,7 +68,6 @@ int test_notEqual_ulps() return Error; } -#endif int main() { @@ -77,11 +75,9 @@ int main() Error += test_equal_epsilon(); Error += test_notEqual_epsilon(); - -#if GLM_LANG & GLM_LANG_CXX11_FLAG + Error += test_equal_ulps(); Error += test_notEqual_ulps(); -#endif - + return Error; } diff --git a/test/ext/ext_vector_relational.cpp b/test/ext/ext_vector_relational.cpp index e6c37bed..df4d7bc4 100644 --- a/test/ext/ext_vector_relational.cpp +++ b/test/ext/ext_vector_relational.cpp @@ -68,10 +68,71 @@ static int test_constexpr() return 0; } +template +static int test_equal_ulps() +{ + typedef glm::vec<4, T, glm::defaultp> vec4; + + T const Zero(0); + T const One(1); + T const Two(2); + + vec4 const Ones(1); + + int Error = 0; + + T const ULP1Plus = std::nextafter(One, Two); + Error += glm::all(glm::equal(Ones, vec4(ULP1Plus), 1)) ? 0 : 1; + + T const ULP2Plus = std::nextafter(ULP1Plus, Two); + Error += !glm::all(glm::equal(Ones, vec4(ULP2Plus), 1)) ? 0 : 1; + + T const ULP1Minus = std::nextafter(One, Zero); + Error += glm::all(glm::equal(Ones, vec4(ULP1Minus), 1)) ? 0 : 1; + + T const ULP2Minus = std::nextafter(ULP1Minus, Zero); + Error += !glm::all(glm::equal(Ones, vec4(ULP2Minus), 1)) ? 0 : 1; + + return Error; +} + +template +static int test_notEqual_ulps() +{ + typedef glm::vec<4, T, glm::defaultp> vec4; + + T const Zero(0); + T const One(1); + T const Two(2); + + vec4 const Ones(1); + + int Error = 0; + + T const ULP1Plus = std::nextafter(One, Two); + Error += !glm::all(glm::notEqual(Ones, vec4(ULP1Plus), 1)) ? 0 : 1; + + T const ULP2Plus = std::nextafter(ULP1Plus, Two); + Error += glm::all(glm::notEqual(Ones, vec4(ULP2Plus), 1)) ? 0 : 1; + + T const ULP1Minus = std::nextafter(One, Zero); + Error += !glm::all(glm::notEqual(Ones, vec4(ULP1Minus), 1)) ? 0 : 1; + + T const ULP2Minus = std::nextafter(ULP1Minus, Zero); + Error += glm::all(glm::notEqual(Ones, vec4(ULP2Minus), 1)) ? 0 : 1; + + return Error; +} + int main() { int Error = 0; + Error += test_equal_ulps(); + Error += test_equal_ulps(); + Error += test_notEqual_ulps(); + Error += test_notEqual_ulps(); + Error += test_equal(); Error += test_equal(); Error += test_equal();