Browse Source

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.
pull/107/head
Vladimír Vondruš 11 years ago
parent
commit
8984904693
  1. 7
      src/Magnum/Math/BoolVector.h
  2. 12
      src/Magnum/Math/Test/BoolVectorTest.cpp
  3. 6
      src/Magnum/Math/Test/VectorTest.cpp
  4. 9
      src/Magnum/Math/Vector2.h
  5. 9
      src/Magnum/Math/Vector3.h
  6. 9
      src/Magnum/Math/Vector4.h

7
src/Magnum/Math/BoolVector.h

@ -93,7 +93,12 @@ template<std::size_t size> class BoolVector {
#ifdef DOXYGEN_GENERATING_OUTPUT
inline explicit BoolVector(T value);
#else
template<class T, class U = typename std::enable_if<std::is_same<bool, T>::value && size != 1, bool>::type> constexpr explicit BoolVector(T value): BoolVector(typename Implementation::GenerateSequence<DataSize>::Type(), value ? FullSegmentMask : 0) {}
template<class T, class U = typename std::enable_if<std::is_same<bool, T>::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<DataSize>::Type(), value ? FullSegmentMask : 0) {}
#endif
/** @brief Copy constructor */

12
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<bool, BoolVector19>::value));

6
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));

9
src/Magnum/Math/Vector2.h

@ -130,7 +130,14 @@ template<class T> 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

9
src/Magnum/Math/Vector3.h

@ -152,7 +152,14 @@ template<class T> 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

9
src/Magnum/Math/Vector4.h

@ -78,7 +78,14 @@ template<class T> 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

Loading…
Cancel
Save