From 5748ef0e7a4a4063eee498070e629285ab62254f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 21 Jul 2024 19:00:27 +0200 Subject: [PATCH] Math: can't have nice things on MSVC. Fuck off, weird buggy compiler. --- src/Magnum/Math/Test/Matrix3Test.cpp | 8 ++++++++ src/Magnum/Math/Test/Matrix4Test.cpp | 8 ++++++++ src/Magnum/Math/Test/MatrixTest.cpp | 8 ++++++++ src/Magnum/Math/Test/RectangularMatrixTest.cpp | 8 ++++++++ 4 files changed, 32 insertions(+) diff --git a/src/Magnum/Math/Test/Matrix3Test.cpp b/src/Magnum/Math/Test/Matrix3Test.cpp index 201163ffd..ac4f8a403 100644 --- a/src/Magnum/Math/Test/Matrix3Test.cpp +++ b/src/Magnum/Math/Test/Matrix3Test.cpp @@ -312,12 +312,20 @@ void Matrix3Test::constructArrayRvalue() { {4.5f, 4.0f, 7.0f}, {1.0f, 2.0f, 3.0f}})); + /* Unfortunately on MSVC (even 2022) this leads to + error C2131: expression did not evaluate to a constant + note: failure was caused by out of range index 3; allowed range is 0 <= index < 2 + and similarly in other tests. Not sure where that comes from, for Vector + this all works, constructArray() above works, and the GCC 4.8 workaround + with fixed size doesn't help here. */ + #ifndef CORRADE_TARGET_MSVC constexpr Matrix3 ca{{{3.0f, 5.0f, 8.0f}, {4.5f, 4.0f, 7.0f}, {1.0f, 2.0f, 3.0f}}}; CORRADE_COMPARE(ca, (Matrix3{{3.0f, 5.0f, 8.0f}, {4.5f, 4.0f, 7.0f}, {1.0f, 2.0f, 3.0f}})); + #endif /* See RectangularMatrixTest::constructArrayRvalue() for details */ #if 0 diff --git a/src/Magnum/Math/Test/Matrix4Test.cpp b/src/Magnum/Math/Test/Matrix4Test.cpp index 7987cf5c4..19f5c4938 100644 --- a/src/Magnum/Math/Test/Matrix4Test.cpp +++ b/src/Magnum/Math/Test/Matrix4Test.cpp @@ -369,6 +369,13 @@ void Matrix4Test::constructArrayRvalue() { {1.0f, 2.0f, 3.0f, -1.0f}, {7.9f, -1.0f, 8.0f, -1.5f}})); + /* Unfortunately on MSVC (even 2022) this leads to + error C2131: expression did not evaluate to a constant + note: failure was caused by out of range index 3; allowed range is 0 <= index < 2 + and similarly in other tests. Not sure where that comes from, for Vector + this all works, constructArray() above works, and the GCC 4.8 workaround + with fixed size doesn't help here. */ + #ifndef CORRADE_TARGET_MSVC constexpr Matrix4 ca{{{3.0f, 5.0f, 8.0f, -3.0f}, {4.5f, 4.0f, 7.0f, 2.0f}, {1.0f, 2.0f, 3.0f, -1.0f}, @@ -377,6 +384,7 @@ void Matrix4Test::constructArrayRvalue() { {4.5f, 4.0f, 7.0f, 2.0f}, {1.0f, 2.0f, 3.0f, -1.0f}, {7.9f, -1.0f, 8.0f, -1.5f}})); + #endif /* See RectangularMatrixTest::constructArrayRvalue() for details */ #if 0 diff --git a/src/Magnum/Math/Test/MatrixTest.cpp b/src/Magnum/Math/Test/MatrixTest.cpp index 2cbb7e726..dbb42723b 100644 --- a/src/Magnum/Math/Test/MatrixTest.cpp +++ b/src/Magnum/Math/Test/MatrixTest.cpp @@ -314,6 +314,13 @@ void MatrixTest::constructArrayRvalue() { Vector4{1.0f, 2.0f, 3.0f, -1.0f}, Vector4{7.9f, -1.0f, 8.0f, -1.5f}})); + /* Unfortunately on MSVC (even 2022) this leads to + error C2131: expression did not evaluate to a constant + note: failure was caused by out of range index 3; allowed range is 0 <= index < 2 + and similarly in other tests. Not sure where that comes from, for Vector + this all works, constructArray() above works, and the GCC 4.8 workaround + with fixed size doesn't help here. */ + #ifndef CORRADE_TARGET_MSVC constexpr Matrix4x4 ca{{{3.0f, 5.0f, 8.0f, -3.0f}, {4.5f, 4.0f, 7.0f, 2.0f}, {1.0f, 2.0f, 3.0f, -1.0f}, @@ -322,6 +329,7 @@ void MatrixTest::constructArrayRvalue() { Vector4{4.5f, 4.0f, 7.0f, 2.0f}, Vector4{1.0f, 2.0f, 3.0f, -1.0f}, Vector4{7.9f, -1.0f, 8.0f, -1.5f}})); + #endif /* See RectangularMatrixTest::constructArrayRvalue() for details */ #if 0 diff --git a/src/Magnum/Math/Test/RectangularMatrixTest.cpp b/src/Magnum/Math/Test/RectangularMatrixTest.cpp index b40b01428..9496c22e4 100644 --- a/src/Magnum/Math/Test/RectangularMatrixTest.cpp +++ b/src/Magnum/Math/Test/RectangularMatrixTest.cpp @@ -333,10 +333,18 @@ void RectangularMatrixTest::constructArrayRvalue() { CORRADE_COMPARE(a, (Matrix2x4{Vector4{3.0f, 5.0f, 8.0f, -3.0f}, Vector4{4.5f, 4.0f, 7.0f, 2.0f}})); + /* Unfortunately on MSVC (even 2022) this leads to + error C2131: expression did not evaluate to a constant + note: failure was caused by out of range index 3; allowed range is 0 <= index < 2 + and similarly in other tests. Not sure where that comes from, for Vector + this all works, constructArray() above works, and the GCC 4.8 workaround + with fixed size doesn't help here. */ + #ifndef CORRADE_TARGET_MSVC constexpr Matrix2x4 ca{{{3.0f, 5.0f, 8.0f, -3.0f}, {4.5f, 4.0f, 7.0f, 2.0f}}}; CORRADE_COMPARE(ca, (Matrix2x4{Vector4{3.0f, 5.0f, 8.0f, -3.0f}, Vector4{4.5f, 4.0f, 7.0f, 2.0f}})); + #endif /* It should always be constructible only with exactly the matching number of elements. As that's checked with a static_assert(), it's impossible