Browse Source

MSVC 2015 compatibility: issues with delegating constexpr tag constructors.

Fixed-size constructors were worked around, the rest is now impossible
to have constexpr.
pull/107/head
Vladimír Vondruš 11 years ago
parent
commit
b2604bb903
  1. 20
      src/Magnum/Math/Matrix3.h
  2. 22
      src/Magnum/Math/Matrix4.h
  3. 24
      src/Magnum/Math/Test/MatrixTest.cpp
  4. 12
      src/Magnum/Math/Test/RectangularMatrixTest.cpp

20
src/Magnum/Math/Matrix3.h

@ -162,8 +162,15 @@ template<class T> class Matrix3: public Matrix3x3<T> {
constexpr /*implicit*/ Matrix3(IdentityInitT = IdentityInit, T value = T{1})
/** @todoc remove workaround when doxygen is sane */
#ifndef DOXYGEN_GENERATING_OUTPUT
/* MSVC 2015 can't handle {} here */
: Matrix3x3<T>(IdentityInit, value)
#ifndef CORRADE_MSVC2015_COMPATIBILITY
: Matrix3x3<T>{IdentityInit, value}
#else
/* Avoid using non-constexpr version, also MSVC 2015 can't handle
{} here */
: Matrix3x3<T>(Vector<3, T>{value, T(0), T(0)},
Vector<3, T>{T(0), value, T(0)},
Vector<3, T>{T(0), T(0), value})
#endif
#endif
{}
@ -171,8 +178,15 @@ template<class T> class Matrix3: public Matrix3x3<T> {
constexpr explicit Matrix3(ZeroInitT)
/** @todoc remove workaround when doxygen is sane */
#ifndef DOXYGEN_GENERATING_OUTPUT
/* MSVC 2015 can't handle {} here */
#ifndef CORRADE_MSVC2015_COMPATIBILITY
: Matrix3x3<T>(ZeroInit)
#else
/* Avoid using non-constexpr version, also MSVC 2015 can't handle
{} here */
: Matrix3x3<T>(Vector<3, T>{T(0), T(0), T(0)},
Vector<3, T>{T(0), T(0), T(0)},
Vector<3, T>{T(0), T(0), T(0)})
#endif
#endif
{}

22
src/Magnum/Math/Matrix4.h

@ -258,8 +258,16 @@ template<class T> class Matrix4: public Matrix4x4<T> {
constexpr /*implicit*/ Matrix4(IdentityInitT = IdentityInit, T value = T{1})
/** @todoc remove workaround when doxygen is sane */
#ifndef DOXYGEN_GENERATING_OUTPUT
/* MSVC 2015 can't handle {} here */
: Matrix4x4<T>(IdentityInit, value)
#ifndef CORRADE_MSVC2015_COMPATIBILITY
: Matrix4x4<T>{IdentityInit, value}
#else
/* Avoid using non-constexpr version, also MSVC 2015 can't handle
{} here */
: Matrix4x4<T>(Vector<4, T>{value, T(0), T(0), T(0)},
Vector<4, T>{T(0), value, T(0), T(0)},
Vector<4, T>{T(0), T(0), value, T(0)},
Vector<4, T>{T(0), T(0), T(0), value})
#endif
#endif
{}
@ -267,8 +275,16 @@ template<class T> class Matrix4: public Matrix4x4<T> {
constexpr explicit Matrix4(ZeroInitT)
/** @todoc remove workaround when doxygen is sane */
#ifndef DOXYGEN_GENERATING_OUTPUT
/* MSVC 2015 can't handle {} here */
#ifndef CORRADE_MSVC2015_COMPATIBILITY
: Matrix4x4<T>(ZeroInit)
#else
/* Avoid using non-constexpr version, also MSVC 2015 can't handle
{} here */
: Matrix4x4<T>(Vector<4, T>{T(0), T(0), T(0), T(0)},
Vector<4, T>{T(0), T(0), T(0), T(0)},
Vector<4, T>{T(0), T(0), T(0), T(0)},
Vector<4, T>{T(0), T(0), T(0), T(0)})
#endif
#endif
{}

24
src/Magnum/Math/Test/MatrixTest.cpp

@ -126,9 +126,21 @@ void MatrixTest::construct() {
}
void MatrixTest::constructIdentity() {
constexpr Matrix4x4 identity;
constexpr Matrix4x4 identity2{IdentityInit};
constexpr Matrix4x4 identity3{IdentityInit, 4.0f};
#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
Matrix4x4 identity;
#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
Matrix4x4 identity2{IdentityInit};
#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
Matrix4x4 identity3{IdentityInit, 4.0f};
Matrix4x4 identityExpected(Vector4(1.0f, 0.0f, 0.0f, 0.0f),
Vector4(0.0f, 1.0f, 0.0f, 0.0f),
@ -146,7 +158,11 @@ void MatrixTest::constructIdentity() {
}
void MatrixTest::constructZero() {
constexpr Matrix4x4 a{ZeroInit};
#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
Matrix4x4 a{ZeroInit};
CORRADE_COMPARE(a, Matrix4x4(Vector4(0.0f, 0.0f, 0.0f, 0.0f),
Vector4(0.0f, 0.0f, 0.0f, 0.0f),
Vector4(0.0f, 0.0f, 0.0f, 0.0f),

12
src/Magnum/Math/Test/RectangularMatrixTest.cpp

@ -149,8 +149,16 @@ void RectangularMatrixTest::construct() {
}
void RectangularMatrixTest::constructDefault() {
constexpr Matrix4x3 a;
constexpr Matrix4x3 b{ZeroInit};
#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
Matrix4x3 a;
#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
Matrix4x3 b{ZeroInit};
CORRADE_COMPARE(a, Matrix4x3(Vector3(0.0f, 0.0f, 0.0f),
Vector3(0.0f, 0.0f, 0.0f),
Vector3(0.0f, 0.0f, 0.0f),

Loading…
Cancel
Save