From 8984904693eaae81546f5425d341d992bedc030b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 6 Sep 2015 21:59:31 +0200 Subject: [PATCH] MSVC 2015 compatibility: single value Math constructor constexpr issues. Some could be worked around, but the rest is prevented by inability to delegate constexpr constructors. --- src/Magnum/Math/BoolVector.h | 7 ++++++- src/Magnum/Math/Test/BoolVectorTest.cpp | 12 ++++++++++-- src/Magnum/Math/Test/VectorTest.cpp | 6 +++++- src/Magnum/Math/Vector2.h | 9 ++++++++- src/Magnum/Math/Vector3.h | 9 ++++++++- src/Magnum/Math/Vector4.h | 9 ++++++++- 6 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/Magnum/Math/BoolVector.h b/src/Magnum/Math/BoolVector.h index d70ba6b43..e3f0e4b77 100644 --- a/src/Magnum/Math/BoolVector.h +++ b/src/Magnum/Math/BoolVector.h @@ -93,7 +93,12 @@ template class BoolVector { #ifdef DOXYGEN_GENERATING_OUTPUT inline explicit BoolVector(T value); #else - template::value && size != 1, bool>::type> constexpr explicit BoolVector(T value): BoolVector(typename Implementation::GenerateSequence::Type(), value ? FullSegmentMask : 0) {} + template::value && size != 1, bool>::type> + #ifndef CORRADE_MSVC2015_COMPATIBILITY + /* Can't use delegating constructors with constexpr -- https://connect.microsoft.com/VisualStudio/feedback/details/1579279/c-constexpr-does-not-work-with-delegating-constructors */ + constexpr + #endif + explicit BoolVector(T value): BoolVector(typename Implementation::GenerateSequence::Type(), value ? FullSegmentMask : 0) {} #endif /** @brief Copy constructor */ diff --git a/src/Magnum/Math/Test/BoolVectorTest.cpp b/src/Magnum/Math/Test/BoolVectorTest.cpp index 2ff19490c..8cde1070e 100644 --- a/src/Magnum/Math/Test/BoolVectorTest.cpp +++ b/src/Magnum/Math/Test/BoolVectorTest.cpp @@ -99,10 +99,18 @@ void BoolVectorTest::constructNoInit() { } void BoolVectorTest::constructOneValue() { - constexpr BoolVector19 a(false); + #ifndef CORRADE_MSVC2015_COMPATIBILITY + /* Can't use delegating constructors with constexpr -- https://connect.microsoft.com/VisualStudio/feedback/details/1579279/c-constexpr-does-not-work-with-delegating-constructors */ + constexpr + #endif + BoolVector19 a(false); CORRADE_COMPARE(a, BoolVector19(0x00, 0x00, 0x00)); - constexpr BoolVector19 b(true); + #ifndef CORRADE_MSVC2015_COMPATIBILITY + /* Can't use delegating constructors with constexpr -- https://connect.microsoft.com/VisualStudio/feedback/details/1579279/c-constexpr-does-not-work-with-delegating-constructors */ + constexpr + #endif + BoolVector19 b(true); CORRADE_COMPARE(b, BoolVector19(0xff, 0xff, 0x07)); CORRADE_VERIFY(!(std::is_convertible::value)); diff --git a/src/Magnum/Math/Test/VectorTest.cpp b/src/Magnum/Math/Test/VectorTest.cpp index c99f2ed05..165640e55 100644 --- a/src/Magnum/Math/Test/VectorTest.cpp +++ b/src/Magnum/Math/Test/VectorTest.cpp @@ -201,7 +201,11 @@ void VectorTest::constructNoInit() { } void VectorTest::constructOneValue() { - constexpr Vector4 a(7.25f); + #ifndef CORRADE_MSVC2015_COMPATIBILITY + /* Can't use delegating constructors with constexpr -- https://connect.microsoft.com/VisualStudio/feedback/details/1579279/c-constexpr-does-not-work-with-delegating-constructors */ + constexpr + #endif + Vector4 a(7.25f); CORRADE_COMPARE(a, Vector4(7.25f, 7.25f, 7.25f, 7.25f)); diff --git a/src/Magnum/Math/Vector2.h b/src/Magnum/Math/Vector2.h index 009abd4b2..4c0302cb2 100644 --- a/src/Magnum/Math/Vector2.h +++ b/src/Magnum/Math/Vector2.h @@ -130,7 +130,14 @@ template class Vector2: public Vector<2, T> { {} /** @copydoc Vector::Vector(T) */ - constexpr explicit Vector2(T value): Vector<2, T>(value) {} + constexpr explicit Vector2(T value): + #ifndef CORRADE_MSVC2015_COMPATIBILITY + Vector<2, T>(value) + #else + /* Avoid using non-constexpr version */ + Vector<2, T>(value, value) + #endif + {} /** * @brief Constructor diff --git a/src/Magnum/Math/Vector3.h b/src/Magnum/Math/Vector3.h index a2b98981c..9fb54127f 100644 --- a/src/Magnum/Math/Vector3.h +++ b/src/Magnum/Math/Vector3.h @@ -152,7 +152,14 @@ template class Vector3: public Vector<3, T> { {} /** @copydoc Vector::Vector(T) */ - constexpr explicit Vector3(T value): Vector<3, T>(value) {} + constexpr explicit Vector3(T value): + #ifndef CORRADE_MSVC2015_COMPATIBILITY + Vector<3, T>(value) + #else + /* Avoid using non-constexpr version */ + Vector<3, T>(value, value, value) + #endif + {} /** * @brief Constructor diff --git a/src/Magnum/Math/Vector4.h b/src/Magnum/Math/Vector4.h index 8ba3d8d26..d4d099587 100644 --- a/src/Magnum/Math/Vector4.h +++ b/src/Magnum/Math/Vector4.h @@ -78,7 +78,14 @@ template class Vector4: public Vector<4, T> { {} /** @copydoc Vector::Vector(T) */ - constexpr explicit Vector4(T value): Vector<4, T>(value) {} + constexpr explicit Vector4(T value): + #ifndef CORRADE_MSVC2015_COMPATIBILITY + Vector<4, T>(value) + #else + /* Avoid using non-constexpr version */ + Vector<4, T>(value, value, value, value) + #endif + {} /** * @brief Constructor