Added GLM_FORCE_SILENT_WARNINGS to silent GLM warnings when using language extensions but using W4 or Wpedantic warnings #814 #775

This commit is contained in:
Christophe Riccio 2018-09-18 22:35:28 +02:00
parent b2a7f1093c
commit 635ff4ef2d
11 changed files with 219 additions and 18 deletions

View File

@ -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

View File

@ -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;

View File

@ -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 --

View File

@ -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 --

View File

@ -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

View File

@ -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 --

View File

@ -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<T>::int_type const DiffULPs = abs(a.i - b.i);
Result[i] = DiffULPs <= MaxULPs;
Result[i] = DiffULPs <= MaxULPs[i];
}
}
return Result;
}
@ -62,12 +64,12 @@ namespace glm
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<L, bool, Q> notEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y, int MaxULPs)
{
return !equal(x, y, MaxULPs);
return notEqual(x, y, vec<L, int, Q>(MaxULPs));
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<L, bool, Q> notEqual(vec<L, T, Q> const& x, vec<L, T, Q> const& y, vec<L, int, Q> const& MaxULPs)
{
return !equal(x, y, MaxULPs);
return not_(equal(x, y, MaxULPs));
}
}//namespace glm

View File

@ -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)
}
```
### <a name="section2_19"></a> 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.
---
<div style="page-break-after: always;"> </div>

View File

@ -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:

View File

@ -1,7 +1,7 @@
#include <glm/ext/scalar_relational.hpp>
#include <cmath>
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()
{
@ -78,10 +76,8 @@ 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;
}

View File

@ -68,10 +68,71 @@ static int test_constexpr()
return 0;
}
template <typename T>
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 <typename T>
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<float>();
Error += test_equal_ulps<double>();
Error += test_notEqual_ulps<float>();
Error += test_notEqual_ulps<double>();
Error += test_equal<glm::vec1>();
Error += test_equal<glm::lowp_vec1>();
Error += test_equal<glm::mediump_vec1>();