Skip to content

Commit

Permalink
Math: workaround MSVC bug with constexpr conversions
Browse files Browse the repository at this point in the history
v2: workaround type suggested by @mosra
  • Loading branch information
sthalik committed Oct 29, 2022
1 parent 38aed19 commit 899f50f
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/Magnum/Math/Test/BezierTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ void BezierTest::convert() {
constexpr QuadraticBezier2D c{a};
CORRADE_COMPARE(c, b);

#if defined(CORRADE_TARGET_MSVC) && CORRADE_CXX_STANDARD >= 202002L
constexpr auto d = QBezier2D(b);
#else
constexpr QBezier2D d(b);
#endif
CORRADE_COMPARE(d.x0, a.x0);
CORRADE_COMPARE(d.x1, a.x1);
CORRADE_COMPARE(d.y0, a.y0);
Expand Down
8 changes: 8 additions & 0 deletions src/Magnum/Math/Test/ColorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,11 @@ void ColorTest::convert() {
Color3 c3(a3);
CORRADE_COMPARE(c3, b3);

#if defined(CORRADE_TARGET_MSVC) && CORRADE_CXX_STANDARD >= 202002L
constexpr auto d3 = Vec3(b3);
#else
constexpr Vec3 d3(b3);
#endif
CORRADE_COMPARE(d3.x, a3.x);
CORRADE_COMPARE(d3.y, a3.y);
CORRADE_COMPARE(d3.z, a3.z);
Expand All @@ -469,7 +473,11 @@ void ColorTest::convert() {
Color4 c4(a4);
CORRADE_COMPARE(c4, b4);

#if defined(CORRADE_TARGET_MSVC) && CORRADE_CXX_STANDARD >= 202002L
constexpr auto d4 = Vec4(b4);
#else
constexpr Vec4 d4(b4);
#endif
CORRADE_COMPARE(d4.x, a4.x);
CORRADE_COMPARE(d4.y, a4.y);
CORRADE_COMPARE(d4.z, a4.z);
Expand Down
4 changes: 4 additions & 0 deletions src/Magnum/Math/Test/ComplexTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,11 @@ void ComplexTest::convert() {
constexpr Complex c(a);
CORRADE_COMPARE(c, b);

#if defined(CORRADE_TARGET_MSVC) && CORRADE_CXX_STANDARD >= 202002L
constexpr auto d = Cmpl(b);
#else
constexpr Cmpl d(b);
#endif
CORRADE_COMPARE(d.re, a.re);
CORRADE_COMPARE(d.im, a.im);

Expand Down
4 changes: 4 additions & 0 deletions src/Magnum/Math/Test/DualComplexTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,11 @@ void DualComplexTest::convert() {
constexpr DualComplex c{a};
CORRADE_COMPARE(c, b);

#if defined(CORRADE_TARGET_MSVC) && CORRADE_CXX_STANDARD >= 202002L
constexpr auto d = DualCmpl(b);
#else
constexpr DualCmpl d(b);
#endif
CORRADE_COMPARE(d.re, a.re);
CORRADE_COMPARE(d.im, a.im);
CORRADE_COMPARE(d.x, a.x);
Expand Down
4 changes: 4 additions & 0 deletions src/Magnum/Math/Test/DualQuaternionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,11 @@ void DualQuaternionTest::convert() {
constexpr DualQuaternion c{a};
CORRADE_COMPARE(c, b);

#if defined(CORRADE_TARGET_MSVC) && CORRADE_CXX_STANDARD >= 202002L
constexpr auto d = DualQuat(b);
#else
constexpr DualQuat d(b);
#endif
CORRADE_COMPARE(d.re.x, a.re.x);
CORRADE_COMPARE(d.re.y, a.re.y);
CORRADE_COMPARE(d.re.z, a.re.z);
Expand Down
4 changes: 4 additions & 0 deletions src/Magnum/Math/Test/FrustumTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,11 @@ void FrustumTest::convert() {
constexpr Frustum c{a};
CORRADE_COMPARE(c, b);

#if defined(CORRADE_TARGET_MSVC) && CORRADE_CXX_STANDARD >= 202002L
constexpr auto d = Frstm(b);
#else
constexpr Frstm d(b);
#endif
CORRADE_COMPARE_AS(Corrade::Containers::arrayView(d.data),
Corrade::Containers::arrayView(a.data),
Corrade::TestSuite::Compare::Container);
Expand Down
8 changes: 6 additions & 2 deletions src/Magnum/Math/Test/Matrix3Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,14 @@ void Matrix3Test::convert() {
constexpr Matrix3 c(b);
CORRADE_COMPARE(c, b);

#ifndef CORRADE_MSVC2015_COMPATIBILITY /* Why can't be conversion constexpr? */
#if defined(CORRADE_TARGET_MSVC) && CORRADE_CXX_STANDARD >= 202002L
constexpr auto d = Mat3(b);
#else
#ifndef CORRADE_MSVC2015_COMPATIBILITY /* Why can't be conversion constexpr? */
constexpr
#endif
#endif
Mat3 d(b);
#endif
for(std::size_t i = 0; i != 9; ++i)
CORRADE_COMPARE(d.a[0], a.a[0]);

Expand Down
8 changes: 6 additions & 2 deletions src/Magnum/Math/Test/Matrix4Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,14 @@ void Matrix4Test::convert() {
constexpr Matrix4 c(b);
CORRADE_COMPARE(c, b);

#ifndef CORRADE_MSVC2015_COMPATIBILITY /* Why can't be conversion constexpr? */
#if defined(CORRADE_TARGET_MSVC) && CORRADE_CXX_STANDARD >= 202002L
constexpr auto d = Mat4(b);
#else
#ifndef CORRADE_MSVC2015_COMPATIBILITY /* Why can't be conversion constexpr? */
constexpr
#endif
#endif
Mat4 d(b);
#endif
for(std::size_t i = 0; i != 16; ++i)
CORRADE_COMPARE(d.a[i], a.a[i]);

Expand Down
4 changes: 4 additions & 0 deletions src/Magnum/Math/Test/MatrixTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,11 @@ void MatrixTest::convert() {
constexpr Matrix3x3 c(b);
CORRADE_COMPARE(c, b);

#if defined(CORRADE_TARGET_MSVC) && CORRADE_CXX_STANDARD >= 202002L
constexpr auto d = Mat3(b);
#else
constexpr Mat3 d(b);
#endif
for(std::size_t i = 0; i != 9; ++i)
CORRADE_COMPARE(d.a[i], a.a[i]);

Expand Down
4 changes: 4 additions & 0 deletions src/Magnum/Math/Test/QuaternionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,11 @@ void QuaternionTest::convert() {
constexpr Quaternion c{a};
CORRADE_COMPARE(c, b);

#if defined(CORRADE_TARGET_MSVC) && CORRADE_CXX_STANDARD >= 202002L
constexpr auto d = Quat(b);
#else
constexpr Quat d(b);
#endif
CORRADE_COMPARE(d.x, a.x);
CORRADE_COMPARE(d.y, a.y);
CORRADE_COMPARE(d.z, a.z);
Expand Down
12 changes: 12 additions & 0 deletions src/Magnum/Math/Test/RangeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,17 +398,29 @@ void RangeTest::convert() {
CORRADE_COMPARE(i, e);
CORRADE_COMPARE(j, f);

#if defined(CORRADE_TARGET_MSVC) && CORRADE_CXX_STANDARD >= 202002L
constexpr auto k = Dim(d);
#else
constexpr Dim k(d);
#endif
CORRADE_COMPARE(k.offset, a.offset);
CORRADE_COMPARE(k.size, a.size);

#if defined(CORRADE_TARGET_MSVC) && CORRADE_CXX_STANDARD >= 202002L
constexpr auto l = Rect(e);
#else
constexpr Rect l(e);
#endif
CORRADE_COMPARE(l.x, b.x);
CORRADE_COMPARE(l.y, b.y);
CORRADE_COMPARE(l.w, b.w);
CORRADE_COMPARE(l.h, b.h);

#if defined(CORRADE_TARGET_MSVC) && CORRADE_CXX_STANDARD >= 202002L
constexpr auto m = Box(f);
#else
constexpr Box m(f);
#endif
CORRADE_COMPARE(m.x, c.x);
CORRADE_COMPARE(m.y, c.y);
CORRADE_COMPARE(m.z, c.z);
Expand Down
4 changes: 4 additions & 0 deletions src/Magnum/Math/Test/RectangularMatrixTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,11 @@ void RectangularMatrixTest::convert() {
constexpr Matrix2x3 c{a};
CORRADE_COMPARE(c, b);

#if defined(CORRADE_TARGET_MSVC) && CORRADE_CXX_STANDARD >= 202002L
constexpr auto d = Mat2x3(b);
#else
constexpr Mat2x3 d(b);
#endif
for(std::size_t i = 0; i != 5; ++i)
CORRADE_COMPARE(d.a[i], a.a[i]);

Expand Down
4 changes: 4 additions & 0 deletions src/Magnum/Math/Test/Vector2Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ void Vector2Test::convert() {
constexpr Vector2 c(a);
CORRADE_COMPARE(c, b);

#if defined(CORRADE_TARGET_MSVC) && CORRADE_CXX_STANDARD >= 202002L
constexpr auto d = Vec2(b);
#else
constexpr Vec2 d(b);
#endif
CORRADE_COMPARE(d.x, a.x);
CORRADE_COMPARE(d.y, a.y);

Expand Down
4 changes: 4 additions & 0 deletions src/Magnum/Math/Test/Vector3Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ void Vector3Test::convert() {
constexpr Vector3 c(a);
CORRADE_COMPARE(c, b);

#if defined(CORRADE_TARGET_MSVC) && CORRADE_CXX_STANDARD >= 202002L
constexpr auto d = Vec3(b);
#else
constexpr Vec3 d(b);
#endif
CORRADE_COMPARE(d.x, a.x);
CORRADE_COMPARE(d.y, a.y);
CORRADE_COMPARE(d.z, a.z);
Expand Down
4 changes: 4 additions & 0 deletions src/Magnum/Math/Test/Vector4Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ void Vector4Test::convert() {
constexpr Vector4 c(a);
CORRADE_COMPARE(c, b);

#if defined(CORRADE_TARGET_MSVC) && CORRADE_CXX_STANDARD >= 202002L
constexpr auto d = Vec4(b);
#else
constexpr Vec4 d(b);
#endif
CORRADE_COMPARE(d.x, a.x);
CORRADE_COMPARE(d.y, a.y);
CORRADE_COMPARE(d.z, a.z);
Expand Down
4 changes: 4 additions & 0 deletions src/Magnum/Math/Test/VectorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,11 @@ void VectorTest::convert() {
constexpr Vector3 c{a};
CORRADE_COMPARE(c, b);

#if defined(CORRADE_TARGET_MSVC) && CORRADE_CXX_STANDARD >= 202002L
constexpr auto d = Vec3(b);
#else
constexpr Vec3 d(b);
#endif
CORRADE_COMPARE(d.x, a.x);
CORRADE_COMPARE(d.y, a.y);
CORRADE_COMPARE(d.z, a.z);
Expand Down

0 comments on commit 899f50f

Please sign in to comment.