Skip to content

Commit

Permalink
Added GLM_FORCE_SILENT_WARNINGS to silent GLM warnings when using lan…
Browse files Browse the repository at this point in the history
…guage extensions but using W4 or Wpedantic warnings #814 #775
  • Loading branch information
Groovounet committed Sep 18, 2018
1 parent b2a7f10 commit 635ff4e
Show file tree
Hide file tree
Showing 11 changed files with 219 additions and 18 deletions.
15 changes: 15 additions & 0 deletions glm/detail/setup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions glm/detail/type_quat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions glm/detail/type_vec1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 --
Expand Down
24 changes: 24 additions & 0 deletions glm/detail/type_vec2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 --
Expand Down
24 changes: 24 additions & 0 deletions glm/detail/type_vec3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions glm/detail/type_vec4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 --
Expand Down
16 changes: 9 additions & 7 deletions glm/ext/vector_relational.inl
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,27 @@ 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[i];
}

// Find the difference in ULPs.
typename detail::float_t<T>::int_type const DiffULPs = abs(a.i - b.i);
Result[i] = DiffULPs <= MaxULPs;
}
return Result;
}

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
6 changes: 6 additions & 0 deletions manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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>

Expand Down
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 6 additions & 10 deletions test/ext/ext_scalar_relational.cpp
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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");
Expand All @@ -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;

Expand All @@ -51,7 +50,7 @@ int test_equal_ulps()
return Error;
}

int test_notEqual_ulps()
static int test_notEqual_ulps()
{
int Error = 0;

Expand All @@ -69,19 +68,16 @@ int test_notEqual_ulps()

return Error;
}
#endif

int main()
{
int Error = 0;

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;
}
Loading

0 comments on commit 635ff4e

Please sign in to comment.