Browse Source

Math: ensure ZeroInit and IdentityInit constructors are explicit.

Like NoInit ones. Not sure what I was doing there.
pull/338/head
Vladimír Vondruš 7 years ago
parent
commit
36ba5f4333
  1. 3
      doc/changelog.dox
  2. 22
      src/Magnum/Math/Angle.h
  3. 11
      src/Magnum/Math/Bezier.h
  4. 9
      src/Magnum/Math/BoolVector.h
  5. 28
      src/Magnum/Math/Color.h
  6. 9
      src/Magnum/Math/Complex.h
  7. 6
      src/Magnum/Math/Dual.h
  8. 11
      src/Magnum/Math/DualComplex.h
  9. 9
      src/Magnum/Math/DualQuaternion.h
  10. 9
      src/Magnum/Math/Frustum.h
  11. 7
      src/Magnum/Math/Half.h
  12. 11
      src/Magnum/Math/Matrix.h
  13. 11
      src/Magnum/Math/Matrix3.h
  14. 11
      src/Magnum/Math/Matrix4.h
  15. 9
      src/Magnum/Math/Quaternion.h
  16. 27
      src/Magnum/Math/Range.h
  17. 9
      src/Magnum/Math/RectangularMatrix.h
  18. 4
      src/Magnum/Math/Test/AngleTest.cpp
  19. 3
      src/Magnum/Math/Test/BezierTest.cpp
  20. 3
      src/Magnum/Math/Test/BoolVectorTest.cpp
  21. 15
      src/Magnum/Math/Test/ColorTest.cpp
  22. 6
      src/Magnum/Math/Test/ComplexTest.cpp
  23. 18
      src/Magnum/Math/Test/CubicHermiteTest.cpp
  24. 6
      src/Magnum/Math/Test/DualComplexTest.cpp
  25. 6
      src/Magnum/Math/Test/DualQuaternionTest.cpp
  26. 4
      src/Magnum/Math/Test/DualTest.cpp
  27. 3
      src/Magnum/Math/Test/FrustumTest.cpp
  28. 3
      src/Magnum/Math/Test/HalfTest.cpp
  29. 6
      src/Magnum/Math/Test/Matrix3Test.cpp
  30. 6
      src/Magnum/Math/Test/Matrix4Test.cpp
  31. 6
      src/Magnum/Math/Test/MatrixTest.cpp
  32. 6
      src/Magnum/Math/Test/QuaternionTest.cpp
  33. 5
      src/Magnum/Math/Test/RangeTest.cpp
  34. 3
      src/Magnum/Math/Test/RectangularMatrixTest.cpp
  35. 3
      src/Magnum/Math/Test/UnitTest.cpp
  36. 3
      src/Magnum/Math/Test/Vector2Test.cpp
  37. 3
      src/Magnum/Math/Test/Vector3Test.cpp
  38. 3
      src/Magnum/Math/Test/Vector4Test.cpp
  39. 3
      src/Magnum/Math/Test/VectorTest.cpp
  40. 9
      src/Magnum/Math/Unit.h
  41. 9
      src/Magnum/Math/Vector.h
  42. 9
      src/Magnum/Math/Vector2.h
  43. 9
      src/Magnum/Math/Vector3.h
  44. 9
      src/Magnum/Math/Vector4.h

3
doc/changelog.dox

@ -187,6 +187,9 @@ See also:
- @ref Math::BoolVector now implements component-wise @cpp && @ce,
@cpp || @ce and @cpp ! @ce for better consistency with boolean operations
done on scalar types
- Construction using @ref Math::ZeroInit and @ref Math::IdentityInit is
now explicit, to be consistent with @ref Math::NoInit construction and
avoid ambiguous cases
@subsubsection changelog-latest-changes-meshtools MeshTools library

22
src/Magnum/Math/Angle.h

@ -98,8 +98,15 @@ These silent errors are easily avoided by requiring explicit conversions:
*/
template<class T> class Deg: public Unit<Deg, T> {
public:
/** @brief Construct zero angle */
constexpr /*implicit*/ Deg(ZeroInitT = ZeroInit) noexcept
/**
* @brief Default constructor
*
* Equivalent to @ref Deg(ZeroInitT).
*/
constexpr /*implicit*/ Deg() noexcept: Unit<Math::Deg, T>{ZeroInit} {}
/** @brief Construct a zero angle */
constexpr explicit Deg(ZeroInitT) noexcept
/** @todoc remove workaround when doxygen is sane */
#ifndef DOXYGEN_GENERATING_OUTPUT
: Unit<Math::Deg, T>{ZeroInit}
@ -170,8 +177,15 @@ See @ref Deg for more information.
*/
template<class T> class Rad: public Unit<Rad, T> {
public:
/** @brief Default constructor */
constexpr /*implicit*/ Rad(ZeroInitT = ZeroInit) noexcept
/**
* @brief Default constructor
*
* Equivalent to @ref Rad(ZeroInitT).
*/
constexpr /*implicit*/ Rad() noexcept: Unit<Math::Rad, T>{ZeroInit} {}
/** @brief Constructor a zero angle */
constexpr explicit Rad(ZeroInitT) noexcept
/** @todoc remove workaround when doxygen is sane */
#ifndef DOXYGEN_GENERATING_OUTPUT
: Unit<Math::Rad, T>{ZeroInit}

11
src/Magnum/Math/Bezier.h

@ -100,9 +100,16 @@ template<UnsignedInt order, UnsignedInt dimensions, class T> class Bezier {
/**
* @brief Default constructor
*
* Construct the curve with all control points being zero vectors.
* Equivalent to @ref Bezier(ZeroInitT).
*/
constexpr /*implicit*/ Bezier(ZeroInitT = ZeroInit) noexcept
constexpr /*implicit*/ Bezier() noexcept: Bezier<order, dimensions, T>{typename Implementation::GenerateSequence<order + 1>::Type{}, ZeroInit} {}
/**
* @brief Construct a zero curve
*
* All control points are zero vectors.
*/
constexpr explicit Bezier(ZeroInitT) noexcept
/** @todoc remove workaround when doxygen is sane */
#ifndef DOXYGEN_GENERATING_OUTPUT
: Bezier<order, dimensions, T>{typename Implementation::GenerateSequence<order + 1>::Type{}, ZeroInit}

9
src/Magnum/Math/BoolVector.h

@ -95,8 +95,15 @@ template<std::size_t size> class BoolVector {
DataSize = (size-1)/8+1 /**< Vector storage size */
};
/**
* @brief Default constructor
*
* Equivalent to @ref BoolVector(ZeroInitT).
*/
constexpr /*implicit*/ BoolVector() noexcept: _data{} {}
/** @brief Construct zero-filled boolean vector */
constexpr /*implicit*/ BoolVector(ZeroInitT = ZeroInit) noexcept: _data{} {}
constexpr explicit BoolVector(ZeroInitT) noexcept: _data{} {}
/** @brief Construct without initializing the contents */
explicit BoolVector(NoInitT) noexcept {}

28
src/Magnum/Math/Color.h

@ -428,9 +428,16 @@ template<class T> class Color3: public Vector3<T> {
/**
* @brief Default constructor
*
* Equivalent to @ref Color3(ZeroInitT).
*/
constexpr /*implicit*/ Color3() noexcept: Vector3<T>{ZeroInit} {}
/**
* @brief Construct a zero color
*
* All components are set to zero.
*/
constexpr /*implicit*/ Color3(ZeroInitT = ZeroInit) noexcept
constexpr explicit Color3(ZeroInitT) noexcept
/** @todoc remove workaround when doxygen is sane */
#ifndef DOXYGEN_GENERATING_OUTPUT
: Vector3<T>{ZeroInit}
@ -833,11 +840,15 @@ class Color4: public Vector4<T> {
/**
* @brief Default constructor
*
* All components are set to zero.
* Equivalent to @ref Color4(ZeroInitT).
*/
constexpr /*implicit*/ Color4() noexcept: Vector4<T>(T(0), T(0), T(0), T(0)) {}
constexpr /*implicit*/ Color4() noexcept: Vector4<T>{ZeroInit} {}
/** @copydoc Vector::Vector(ZeroInitT) */
/**
* @brief Construct a zero color
*
* All components are set to zero.
*/
constexpr explicit Color4(ZeroInitT) noexcept
/** @todoc remove workaround when doxygen is sane */
#ifndef DOXYGEN_GENERATING_OUTPUT
@ -1042,9 +1053,16 @@ template<class T> struct ColorHsv {
/**
* @brief Default constructor
*
* Equivalent to @ref ColorHsv(ZeroInitT).
*/
constexpr /*implicit*/ ColorHsv() noexcept: hue{}, saturation{}, value{} {}
/**
* @brief Construct a zero color
*
* All members are set to zero.
*/
constexpr /*implicit*/ ColorHsv(ZeroInitT = ZeroInit) noexcept: hue{}, saturation{}, value{} {}
constexpr explicit ColorHsv(ZeroInitT) noexcept: hue{}, saturation{}, value{} {}
/** @brief Construct without initializing the contents */
explicit ColorHsv(NoInitT) noexcept: hue{NoInit} /* and the others not */ {}

9
src/Magnum/Math/Complex.h

@ -124,11 +124,18 @@ template<class T> class Complex {
/**
* @brief Default constructor
*
* Equivalent to @ref Complex(IdentityInitT).
*/
constexpr /*implicit*/ Complex() noexcept: _real(T(1)), _imaginary(T(0)) {}
/**
* @brief Identity constructor
*
* Constructs unit complex number. @f[
* c = 1 + i0
* @f]
*/
constexpr /*implicit*/ Complex(IdentityInitT = IdentityInit) noexcept: _real(T(1)), _imaginary(T(0)) {}
constexpr explicit Complex(IdentityInitT) noexcept: _real(T(1)), _imaginary(T(0)) {}
/** @brief Construct zero-initialized complex number */
constexpr explicit Complex(ZeroInitT) noexcept: _real{}, _imaginary{} {}

6
src/Magnum/Math/Dual.h

@ -69,11 +69,11 @@ template<class T> class Dual {
/** @brief Construct zero-initialized dual number */
#ifdef DOXYGEN_GENERATING_OUTPUT
constexpr /*implicit*/ Dual(ZeroInitT) noexcept;
constexpr explicit Dual(ZeroInitT) noexcept;
#else
/* MSVC 2015 can't handle {} instead of ::value */
template<class U = T, class = typename std::enable_if<std::is_pod<U>::value>::type> constexpr /*implicit*/ Dual(ZeroInitT) noexcept: _real{}, _dual{} {}
template<class U = T, class V = T, class = typename std::enable_if<std::is_constructible<U, ZeroInitT>::value>::type> constexpr /*implicit*/ Dual(ZeroInitT) noexcept: _real{ZeroInit}, _dual{ZeroInit} {}
template<class U = T, class = typename std::enable_if<std::is_pod<U>::value>::type> constexpr explicit Dual(ZeroInitT) noexcept: _real{}, _dual{} {}
template<class U = T, class V = T, class = typename std::enable_if<std::is_constructible<U, ZeroInitT>::value>::type> constexpr explicit Dual(ZeroInitT) noexcept: _real{ZeroInit}, _dual{ZeroInit} {}
#endif
/** @brief Construct without initializing the contents */

11
src/Magnum/Math/DualComplex.h

@ -105,14 +105,21 @@ template<class T> class DualComplex: public Dual<Complex<T>> {
/**
* @brief Default constructor
*
* Equivalent to @ref DualComplex(IdentityInitT).
*/
constexpr /*implicit*/ DualComplex() noexcept: Dual<Complex<T>>({}, {T(0), T(0)}) {}
/**
* @brief Identity constructor
*
* Creates unit dual complex number. @f[
* \hat c = (0 + i1) + \epsilon (0 + i0)
* @f]
*/
#ifdef DOXYGEN_GENERATING_OUTPUT
constexpr /*implicit*/ DualComplex(IdentityInitT = IdentityInit) noexcept;
constexpr explicit DualComplex(IdentityInitT) noexcept;
#else
constexpr /*implicit*/ DualComplex(IdentityInitT = IdentityInit) noexcept: Dual<Complex<T>>({}, {T(0), T(0)}) {}
constexpr explicit DualComplex(IdentityInitT) noexcept: Dual<Complex<T>>({}, {T(0), T(0)}) {}
#endif
/** @brief Construct zero-initialized dual complex number */

9
src/Magnum/Math/DualQuaternion.h

@ -245,11 +245,18 @@ template<class T> class DualQuaternion: public Dual<Quaternion<T>> {
/**
* @brief Default constructor
*
* Equivalent to @ref DualQuaternion(IdentityInitT).
*/
constexpr /*implicit*/ DualQuaternion() noexcept: Dual<Quaternion<T>>{{}, {{}, T(0)}} {}
/**
* @brief Identity constructor
*
* Creates unit dual quaternion. @f[
* \hat q = [\boldsymbol 0, 1] + \epsilon [\boldsymbol 0, 0]
* @f]
*/
constexpr /*implicit*/ DualQuaternion(IdentityInitT = IdentityInit) noexcept
constexpr explicit DualQuaternion(IdentityInitT) noexcept
/** @todoc remove workaround when doxygen is sane */
#ifndef DOXYGEN_GENERATING_OUTPUT
: Dual<Quaternion<T>>{{}, {{}, T(0)}}

9
src/Magnum/Math/Frustum.h

@ -69,13 +69,20 @@ template<class T> class Frustum {
m.row(3) - m.row(2)};
}
/**
* @brief Default constructor
*
* Equivalent to @ref Frustum(IdentityInitT).
*/
constexpr /*implicit*/ Frustum() noexcept: Frustum<T>{IdentityInit} {}
/**
* @brief Identity constructor
*
* Equivalent to creating a frustum from an identity matrix.
* @see @ref fromMatrix()
*/
constexpr /*implicit*/ Frustum(IdentityInitT = IdentityInit) noexcept;
constexpr explicit Frustum(IdentityInitT) noexcept;
/** @brief Construct a frustum without initializing the contents */
explicit Frustum(NoInitT) noexcept: _data{Vector4<T>{NoInit}, Vector4<T>{NoInit}, Vector4<T>{NoInit}, Vector4<T>{NoInit}, Vector4<T>{NoInit}, Vector4<T>{NoInit}} {}

7
src/Magnum/Math/Half.h

@ -64,9 +64,12 @@ class Half {
/**
* @brief Default constructor
*
* Creates a zero value.
* Equivalent to @ref Half(ZeroInitT).
*/
constexpr /*implicit*/ Half(ZeroInitT = ZeroInit) noexcept: _data{} {}
constexpr /*implicit*/ Half() noexcept: _data{} {}
/** @brief Construct a zero value */
constexpr explicit Half(ZeroInitT) noexcept: _data{} {}
/** @brief Construct a half value from underlying 16-bit representation */
constexpr explicit Half(UnsignedShort data) noexcept: _data{data} {}

11
src/Magnum/Math/Matrix.h

@ -65,10 +65,17 @@ template<std::size_t size, class T> class Matrix: public RectangularMatrix<size,
/**
* @brief Default constructor
*
* Creates identity matrix. @p value allows you to specify value on
* Equivalent to @ref Matrix(IdentityInitT, T).
*/
constexpr /*implicit*/ Matrix() noexcept: RectangularMatrix<size, size, T>{typename Implementation::GenerateSequence<size>::Type(), Vector<size, T>(T(1))} {}
/**
* @brief Identity constructor
*
* Creates an identity matrix. @p value allows you to specify value on
* diagonal.
*/
constexpr /*implicit*/ Matrix(IdentityInitT = IdentityInit, T value = T(1)) noexcept
constexpr explicit Matrix(IdentityInitT, T value = T(1)) noexcept
/** @todoc remove workaround when doxygen is sane */
#ifndef DOXYGEN_GENERATING_OUTPUT
: RectangularMatrix<size, size, T>{typename Implementation::GenerateSequence<size>::Type(), Vector<size, T>(value)}

11
src/Magnum/Math/Matrix3.h

@ -198,10 +198,17 @@ template<class T> class Matrix3: public Matrix3x3<T> {
/**
* @brief Default constructor
*
* Creates identity matrix. @p value allows you to specify value on
* Equivalent to @ref Matrix3(IdentityInitT, T).
*/
constexpr /*implicit*/ Matrix3() noexcept: Matrix3x3<T>{IdentityInit, T(1)} {}
/**
* @brief Identity constructor
*
* Creates an identity matrix. @p value allows you to specify value on
* diagonal.
*/
constexpr /*implicit*/ Matrix3(IdentityInitT = IdentityInit, T value = T{1}) noexcept
constexpr explicit Matrix3(IdentityInitT, T value = T{1}) noexcept
/** @todoc remove workaround when doxygen is sane */
#ifndef DOXYGEN_GENERATING_OUTPUT
: Matrix3x3<T>{IdentityInit, value}

11
src/Magnum/Math/Matrix4.h

@ -383,10 +383,17 @@ template<class T> class Matrix4: public Matrix4x4<T> {
/**
* @brief Default constructor
*
* Creates identity matrix. @p value allows you to specify value on
* Equivalent to @ref Matrix4(IdentityInitT, T).
*/
constexpr /*implicit*/ Matrix4() noexcept: Matrix4x4<T>{IdentityInit, T(1)} {}
/**
* @brief Identity constructor
*
* Creates an identity matrix. @p value allows you to specify value on
* diagonal.
*/
constexpr /*implicit*/ Matrix4(IdentityInitT = IdentityInit, T value = T{1}) noexcept
constexpr explicit Matrix4(IdentityInitT, T value = T{1}) noexcept
/** @todoc remove workaround when doxygen is sane */
#ifndef DOXYGEN_GENERATING_OUTPUT
: Matrix4x4<T>{IdentityInit, value}

9
src/Magnum/Math/Quaternion.h

@ -270,11 +270,18 @@ template<class T> class Quaternion {
/**
* @brief Default constructor
*
* Equivalent to @ref Quaternion(IdentityInitT).
*/
constexpr /*implicit*/ Quaternion() noexcept: _scalar{T(1)} {}
/**
* @brief Identity constructor
*
* Creates unit quaternion. @f[
* q = [\boldsymbol 0, 1]
* @f]
*/
constexpr /*implicit*/ Quaternion(IdentityInitT = IdentityInit) noexcept: _scalar{T(1)} {}
constexpr explicit Quaternion(IdentityInitT) noexcept: _scalar{T(1)} {}
/** @brief Construct zero-initialized quaternion */
constexpr explicit Quaternion(ZeroInitT) noexcept: _vector{ZeroInit}, _scalar{T{0}} {}

27
src/Magnum/Math/Range.h

@ -96,12 +96,19 @@ template<UnsignedInt dimensions, class T> class Range {
return {center - halfSize, center + halfSize};
}
/**
* @brief Default constructor
*
* Equivalent to @ref Range(ZeroInitT).
*/
constexpr /*implicit*/ Range() noexcept: Range<dimensions, T>{ZeroInit, typename std::conditional<dimensions == 1, void*, ZeroInitT*>::type{}} {}
/**
* @brief Construct zero range
*
* Construct zero-size range positioned at origin.
*/
constexpr /*implicit*/ Range(ZeroInitT = ZeroInit) noexcept: Range<dimensions, T>{ZeroInit, typename std::conditional<dimensions == 1, void*, ZeroInitT*>::type{}} {}
constexpr explicit Range(ZeroInitT) noexcept: Range<dimensions, T>{ZeroInit, typename std::conditional<dimensions == 1, void*, ZeroInitT*>::type{}} {}
/** @brief Construct without initializing the contents */
explicit Range(NoInitT) noexcept: Range<dimensions, T>{NoInit, typename std::conditional<dimensions == 1, void*, NoInitT*>::type{}} {}
@ -351,8 +358,15 @@ See @ref Range for more information.
*/
template<class T> class Range2D: public Range<2, T> {
public:
/**
* @brief Default constructor
*
* Equivalent to @ref Range2D(ZeroInitT).
*/
constexpr /*implicit*/ Range2D() noexcept: Range<2, T>{ZeroInit} {}
/** @copydoc Range(ZeroInitT) */
constexpr /*implicit*/ Range2D(ZeroInitT = ZeroInit) noexcept
constexpr explicit Range2D(ZeroInitT) noexcept
/** @todoc remove workaround when doxygen is sane */
#ifndef DOXYGEN_GENERATING_OUTPUT
: Range<2, T>{ZeroInit}
@ -494,8 +508,15 @@ See @ref Range for more information.
*/
template<class T> class Range3D: public Range<3, T> {
public:
/**
* @brief Default constructor
*
* Equivalent to @ref Range3D(ZeroInitT).
*/
constexpr /*implicit*/ Range3D() noexcept: Range<3, T>{ZeroInit} {}
/** @copydoc Range(ZeroInitT) */
constexpr /*implicit*/ Range3D(ZeroInitT = ZeroInit) noexcept
constexpr explicit Range3D(ZeroInitT) noexcept
/** @todoc remove workaround when doxygen is sane */
#ifndef DOXYGEN_GENERATING_OUTPUT
: Range<3, T>{ZeroInit}

9
src/Magnum/Math/RectangularMatrix.h

@ -107,8 +107,15 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
return RectangularMatrix(typename Implementation::GenerateSequence<cols>::Type(), diagonal);
}
/**
* @brief Default constructor
*
* Equivalent to @ref RectangularMatrix(ZeroInitT).
*/
constexpr /*implicit*/ RectangularMatrix() noexcept: RectangularMatrix<cols, rows, T>{typename Implementation::GenerateSequence<cols>::Type{}, ZeroInit} {}
/** @brief Construct zero-filled matrix */
constexpr /*implicit*/ RectangularMatrix(ZeroInitT = ZeroInit) noexcept
constexpr explicit RectangularMatrix(ZeroInitT) noexcept
/** @todoc remove workaround when doxygen is sane */
#ifndef DOXYGEN_GENERATING_OUTPUT
: RectangularMatrix<cols, rows, T>{typename Implementation::GenerateSequence<cols>::Type{}, ZeroInit}

4
src/Magnum/Math/Test/AngleTest.cpp

@ -170,6 +170,10 @@ void AngleTest::constructDefault() {
CORRADE_VERIFY(std::is_nothrow_default_constructible<Rad>::value);
CORRADE_VERIFY((std::is_nothrow_constructible<Deg, ZeroInitT>::value));
CORRADE_VERIFY((std::is_nothrow_constructible<Rad, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, Deg>::value));
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, Rad>::value));
}
void AngleTest::constructNoInit() {

3
src/Magnum/Math/Test/BezierTest.cpp

@ -132,6 +132,9 @@ void BezierTest::constructDefault() {
CORRADE_VERIFY(std::is_nothrow_default_constructible<QuadraticBezier2D>::value);
CORRADE_VERIFY((std::is_nothrow_constructible<QuadraticBezier2D, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, QuadraticBezier2D>::value));
}
void BezierTest::constructNoInit() {

3
src/Magnum/Math/Test/BoolVectorTest.cpp

@ -129,6 +129,9 @@ void BoolVectorTest::constructDefault() {
CORRADE_VERIFY(std::is_nothrow_default_constructible<BoolVector19>::value);
CORRADE_VERIFY((std::is_nothrow_constructible<BoolVector19, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, BoolVector19>::value));
}
void BoolVectorTest::constructNoInit() {

15
src/Magnum/Math/Test/ColorTest.cpp

@ -290,12 +290,12 @@ void ColorTest::construct() {
void ColorTest::constructDefault() {
constexpr Color3 a1;
constexpr Color3 a2{Math::ZeroInit};
constexpr Color3 a2{ZeroInit};
CORRADE_COMPARE(a1, Color3(0.0f, 0.0f, 0.0f));
CORRADE_COMPARE(a2, Color3(0.0f, 0.0f, 0.0f));
constexpr Color4 b1;
constexpr Color4 b2{Math::ZeroInit};
constexpr Color4 b2{ZeroInit};
CORRADE_COMPARE(b1, Color4(0.0f, 0.0f, 0.0f, 0.0f));
CORRADE_COMPARE(b2, Color4(0.0f, 0.0f, 0.0f, 0.0f));
@ -306,13 +306,17 @@ void ColorTest::constructDefault() {
CORRADE_VERIFY(std::is_nothrow_default_constructible<Color4>::value);
CORRADE_VERIFY((std::is_nothrow_constructible<Color3, ZeroInitT>::value));
CORRADE_VERIFY((std::is_nothrow_constructible<Color4, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, Color3>::value));
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, Color4>::value));
}
void ColorTest::constructNoInit() {
Color3 a{1.0f, 0.5f, 0.75f};
Color4 b{1.0f, 0.5f, 0.75f, 0.5f};
new(&a) Color3{Math::NoInit};
new(&b) Color4{Math::NoInit};
new(&a) Color3{NoInit};
new(&b) Color4{NoInit};
{
#if defined(__GNUC__) && __GNUC__*100 + __GNUC_MINOR__ >= 601 && __OPTIMIZE__
CORRADE_EXPECT_FAIL("GCC 6.1+ misoptimizes and overwrites the value.");
@ -481,6 +485,9 @@ void ColorTest::constructHsvDefault() {
CORRADE_VERIFY(std::is_nothrow_default_constructible<ColorHsv>::value);
CORRADE_VERIFY((std::is_nothrow_constructible<ColorHsv, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, ColorHsv>::value));
}
void ColorTest::constructHsvNoInit() {

6
src/Magnum/Math/Test/ComplexTest.cpp

@ -185,6 +185,9 @@ void ComplexTest::constructIdentity() {
CORRADE_VERIFY(std::is_nothrow_default_constructible<Complex>::value);
CORRADE_VERIFY((std::is_nothrow_constructible<Complex, IdentityInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<IdentityInitT, Complex>::value));
}
void ComplexTest::constructZero() {
@ -192,6 +195,9 @@ void ComplexTest::constructZero() {
CORRADE_COMPARE(a, Complex(0.0f, 0.0f));
CORRADE_VERIFY((std::is_nothrow_constructible<Complex, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, Complex>::value));
}
void ComplexTest::constructNoInit() {

18
src/Magnum/Math/Test/CubicHermiteTest.cpp

@ -339,6 +339,9 @@ void CubicHermiteTest::constructZeroScalar() {
CORRADE_COMPARE(b, (CubicHermite1D{0.0f, 0.0f, 0.0f}));
CORRADE_VERIFY((std::is_nothrow_constructible<CubicHermite1D, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, CubicHermite1D>::value));
}
void CubicHermiteTest::constructZeroVector() {
@ -349,6 +352,9 @@ void CubicHermiteTest::constructZeroVector() {
CORRADE_COMPARE(b, (CubicHermite2D{{0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}}));
CORRADE_VERIFY((std::is_nothrow_constructible<CubicHermite2D, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, CubicHermite2D>::value));
}
void CubicHermiteTest::constructZeroComplex() {
@ -359,6 +365,9 @@ void CubicHermiteTest::constructZeroComplex() {
CORRADE_COMPARE(b, (CubicHermiteComplex{{0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}}));
CORRADE_VERIFY((std::is_nothrow_constructible<CubicHermiteComplex, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, CubicHermiteComplex>::value));
}
void CubicHermiteTest::constructZeroQuaternion() {
@ -375,6 +384,9 @@ void CubicHermiteTest::constructZeroQuaternion() {
{{0.0f, 0.0f, 0.0f}, 0.0f}}));
CORRADE_VERIFY((std::is_nothrow_constructible<CubicHermiteQuaternion, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, CubicHermiteQuaternion>::value));
}
void CubicHermiteTest::constructIdentityScalar() {
@ -393,6 +405,9 @@ void CubicHermiteTest::constructIdentityComplex() {
CORRADE_COMPARE(b, (CubicHermiteComplex{{0.0f, 0.0f}, {1.0f, 0.0f}, {0.0f, 0.0f}}));
CORRADE_VERIFY((std::is_nothrow_constructible<CubicHermiteComplex, IdentityInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<IdentityInitT, CubicHermiteComplex>::value));
}
void CubicHermiteTest::constructIdentityQuaternion() {
@ -409,6 +424,9 @@ void CubicHermiteTest::constructIdentityQuaternion() {
{{0.0f, 0.0f, 0.0f}, 0.0f}}));
CORRADE_VERIFY((std::is_nothrow_constructible<CubicHermiteComplex, IdentityInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<IdentityInitT, CubicHermiteQuaternion>::value));
}
void CubicHermiteTest::constructNoInitScalar() {

6
src/Magnum/Math/Test/DualComplexTest.cpp

@ -176,6 +176,9 @@ void DualComplexTest::constructIdentity() {
CORRADE_VERIFY(std::is_nothrow_default_constructible<DualComplex>::value);
CORRADE_VERIFY((std::is_nothrow_constructible<DualComplex, IdentityInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<IdentityInitT, DualComplex>::value));
}
void DualComplexTest::constructZero() {
@ -183,6 +186,9 @@ void DualComplexTest::constructZero() {
CORRADE_COMPARE(a, DualComplex({0.0f, 0.0f}, {0.0f, 0.0f}));
CORRADE_VERIFY((std::is_nothrow_constructible<DualComplex, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, DualComplex>::value));
}
void DualComplexTest::constructNoInit() {

6
src/Magnum/Math/Test/DualQuaternionTest.cpp

@ -201,6 +201,9 @@ void DualQuaternionTest::constructIdentity() {
CORRADE_VERIFY(std::is_nothrow_default_constructible<DualQuaternion>::value);
CORRADE_VERIFY((std::is_nothrow_constructible<DualQuaternion, IdentityInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<IdentityInitT, DualQuaternion>::value));
}
void DualQuaternionTest::constructZero() {
@ -208,6 +211,9 @@ void DualQuaternionTest::constructZero() {
CORRADE_COMPARE(a, DualQuaternion({{0.0f, 0.0f, 0.0f}, 0.0f}, {{0.0f, 0.0f, 0.0f}, 0.0f}));
CORRADE_VERIFY((std::is_nothrow_constructible<DualQuaternion, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, DualQuaternion>::value));
}
void DualQuaternionTest::constructNoInit() {

4
src/Magnum/Math/Test/DualTest.cpp

@ -138,6 +138,10 @@ void DualTest::constructZero() {
CORRADE_VERIFY((std::is_nothrow_constructible<Dual, ZeroInitT>::value));
CORRADE_VERIFY((std::is_nothrow_constructible<Math::Dual<Math::Quaternion<Float>>, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, Dual>::value));
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, Math::Dual<Math::Quaternion<Float>>>::value));
}
void DualTest::constructNoInit() {

3
src/Magnum/Math/Test/FrustumTest.cpp

@ -150,6 +150,9 @@ void FrustumTest::constructIdentity() {
CORRADE_VERIFY(std::is_nothrow_default_constructible<Frustum>::value);
CORRADE_VERIFY((std::is_nothrow_constructible<Frustum, IdentityInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<IdentityInitT, Frustum>::value));
}
void FrustumTest::constructNoInit() {

3
src/Magnum/Math/Test/HalfTest.cpp

@ -564,6 +564,9 @@ void HalfTest::constructDefault() {
CORRADE_VERIFY((std::is_nothrow_default_constructible<Half>::value));
CORRADE_VERIFY((std::is_nothrow_constructible<Half, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, Half>::value));
}
void HalfTest::constructValue() {

6
src/Magnum/Math/Test/Matrix3Test.cpp

@ -184,6 +184,9 @@ void Matrix3Test::constructIdentity() {
CORRADE_VERIFY(std::is_nothrow_default_constructible<Matrix3>::value);
CORRADE_VERIFY((std::is_nothrow_constructible<Matrix3, IdentityInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<IdentityInitT, Matrix3>::value));
}
void Matrix3Test::constructZero() {
@ -193,6 +196,9 @@ void Matrix3Test::constructZero() {
{0.0f, 0.0f, 0.0f}));
CORRADE_VERIFY((std::is_nothrow_constructible<Matrix3, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, Matrix3>::value));
}
void Matrix3Test::constructNoInit() {

6
src/Magnum/Math/Test/Matrix4Test.cpp

@ -217,6 +217,9 @@ void Matrix4Test::constructIdentity() {
CORRADE_VERIFY(std::is_nothrow_default_constructible<Matrix4>::value);
CORRADE_VERIFY((std::is_nothrow_constructible<Matrix4, IdentityInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<IdentityInitT, Matrix4>::value));
}
void Matrix4Test::constructZero() {
@ -227,6 +230,9 @@ void Matrix4Test::constructZero() {
{0.0f, 0.0f, 0.0f, 0.0f}));
CORRADE_VERIFY((std::is_nothrow_constructible<Matrix4, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, Matrix4>::value));
}
void Matrix4Test::constructNoInit() {

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

@ -161,6 +161,9 @@ void MatrixTest::constructIdentity() {
CORRADE_VERIFY(std::is_nothrow_default_constructible<Matrix4x4>::value);
CORRADE_VERIFY((std::is_nothrow_constructible<Matrix4x4, IdentityInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<IdentityInitT, Matrix4x4>::value));
}
void MatrixTest::constructZero() {
@ -171,6 +174,9 @@ void MatrixTest::constructZero() {
Vector4(0.0f, 0.0f, 0.0f, 0.0f)));
CORRADE_VERIFY((std::is_nothrow_constructible<Matrix4x4, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, Matrix4x4>::value));
}
void MatrixTest::constructNoInit() {

6
src/Magnum/Math/Test/QuaternionTest.cpp

@ -211,6 +211,9 @@ void QuaternionTest::constructIdentity() {
CORRADE_VERIFY(std::is_nothrow_default_constructible<Quaternion>::value);
CORRADE_VERIFY((std::is_nothrow_constructible<Quaternion, IdentityInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<IdentityInitT, Quaternion>::value));
}
void QuaternionTest::constructZero() {
@ -218,6 +221,9 @@ void QuaternionTest::constructZero() {
CORRADE_COMPARE(a, Quaternion({0.0f, 0.0f, 0.0f}, 0.0f));
CORRADE_VERIFY((std::is_nothrow_constructible<Quaternion, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, Quaternion>::value));
}
void QuaternionTest::constructNoInit() {

5
src/Magnum/Math/Test/RangeTest.cpp

@ -231,6 +231,11 @@ void RangeTest::constructDefault() {
CORRADE_VERIFY((std::is_nothrow_constructible<Range1Di, ZeroInitT>::value));
CORRADE_VERIFY((std::is_nothrow_constructible<Range2Di, ZeroInitT>::value));
CORRADE_VERIFY((std::is_nothrow_constructible<Range3Di, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, Range1Di>::value));
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, Range2Di>::value));
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, Range3Di>::value));
}
void RangeTest::constructNoInit() {

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

@ -174,6 +174,9 @@ void RectangularMatrixTest::constructDefault() {
CORRADE_VERIFY(std::is_nothrow_default_constructible<Matrix4x3>::value);
CORRADE_VERIFY((std::is_nothrow_constructible<Matrix4x3, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, Matrix4x3>::value));
}
void RectangularMatrixTest::constructNoInit() {

3
src/Magnum/Math/Test/UnitTest.cpp

@ -87,6 +87,9 @@ void UnitTest::constructDefault() {
CORRADE_VERIFY(std::is_nothrow_default_constructible<Sec>::value);
CORRADE_VERIFY((std::is_nothrow_constructible<Sec, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, Sec>::value));
}
void UnitTest::constructNoInit() {

3
src/Magnum/Math/Test/Vector2Test.cpp

@ -117,6 +117,9 @@ void Vector2Test::constructDefault() {
CORRADE_VERIFY(std::is_nothrow_default_constructible<Vector2>::value);
CORRADE_VERIFY((std::is_nothrow_constructible<Vector2, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, Vector2>::value));
}
void Vector2Test::constructNoInit() {

3
src/Magnum/Math/Test/Vector3Test.cpp

@ -117,6 +117,9 @@ void Vector3Test::constructDefault() {
CORRADE_VERIFY(std::is_nothrow_default_constructible<Vector3>::value);
CORRADE_VERIFY((std::is_nothrow_constructible<Vector3, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, Vector3>::value));
}
void Vector3Test::constructNoInit() {

3
src/Magnum/Math/Test/Vector4Test.cpp

@ -138,6 +138,9 @@ void Vector4Test::constructDefault() {
CORRADE_VERIFY(std::is_nothrow_default_constructible<Vector4>::value);
CORRADE_VERIFY((std::is_nothrow_constructible<Vector4, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, Vector4>::value));
}
void Vector4Test::constructNoInit() {

3
src/Magnum/Math/Test/VectorTest.cpp

@ -210,6 +210,9 @@ void VectorTest::constructDefault() {
CORRADE_VERIFY(std::is_nothrow_default_constructible<Vector4>::value);
CORRADE_VERIFY((std::is_nothrow_constructible<Vector4, ZeroInitT>::value));
/* Implicit construction is not allowed */
CORRADE_VERIFY(!(std::is_convertible<ZeroInitT, Vector4>::value));
}
void VectorTest::constructNoInit() {

9
src/Magnum/Math/Unit.h

@ -46,8 +46,15 @@ template<template<class> class Derived, class T> class Unit {
public:
typedef T Type; /**< @brief Underlying data type */
/**
* @brief Default constructor
*
* Equivalent to @ref Unit(ZeroInitT).
*/
constexpr /*implicit*/ Unit() noexcept: _value(T(0)) {}
/** @brief Construct zero value */
constexpr /*implicit*/ Unit(ZeroInitT = ZeroInit) noexcept: _value(T(0)) {}
constexpr explicit Unit(ZeroInitT) noexcept: _value(T(0)) {}
/** @brief Construct without initializing the contents */
explicit Unit(NoInitT) noexcept {}

9
src/Magnum/Math/Vector.h

@ -165,11 +165,18 @@ template<std::size_t size, class T> class Vector {
/**
* @brief Default constructor
*
* Equivalent to @ref Vector(ZeroInitT).
*/
constexpr /*implicit*/ Vector() noexcept: _data{} {}
/**
* @brief Construct a zero vector
*
* @f[
* \boldsymbol v = \boldsymbol 0
* @f]
*/
constexpr /*implicit*/ Vector(ZeroInitT = ZeroInit) noexcept: _data{} {}
constexpr explicit Vector(ZeroInitT) noexcept: _data{} {}
/** @brief Construct vector without initializing the contents */
explicit Vector(NoInitT) noexcept {}

9
src/Magnum/Math/Vector2.h

@ -100,8 +100,15 @@ template<class T> class Vector2: public Vector<2, T> {
*/
constexpr static Vector2<T> yScale(T scale) { return {T(1), scale}; }
/**
* @brief Default constructor
*
* Equivalent to @ref Vector2(ZeroInitT).
*/
constexpr /*implicit*/ Vector2() noexcept: Vector<2, T>{ZeroInit} {}
/** @copydoc Vector::Vector(ZeroInitT) */
constexpr /*implicit*/ Vector2(ZeroInitT = ZeroInit) noexcept
constexpr explicit Vector2(ZeroInitT) noexcept
/** @todoc remove workaround when doxygen is sane */
#ifndef DOXYGEN_GENERATING_OUTPUT
: Vector<2, T>{ZeroInit}

9
src/Magnum/Math/Vector3.h

@ -121,8 +121,15 @@ template<class T> class Vector3: public Vector<3, T> {
*/
constexpr static Vector3<T> zScale(T scale) { return {T(1), T(1), scale}; }
/**
* @brief Default constructor
*
* Equivalent to @ref Vector3(ZeroInitT).
*/
constexpr /*implicit*/ Vector3() noexcept: Vector<3, T>{ZeroInit} {}
/** @copydoc Vector::Vector(ZeroInitT) */
constexpr /*implicit*/ Vector3(ZeroInitT = ZeroInit) noexcept
constexpr explicit Vector3(ZeroInitT) noexcept
/** @todoc remove workaround when doxygen is sane */
#ifndef DOXYGEN_GENERATING_OUTPUT
: Vector<3, T>{ZeroInit}

9
src/Magnum/Math/Vector4.h

@ -59,8 +59,15 @@ template<class T> class Vector4: public Vector<4, T> {
3 < otherSize ? a[3] : w};
}
/**
* @brief Default constructor
*
* Equivalent to @ref Vector4(ZeroInitT).
*/
constexpr /*implicit*/ Vector4() noexcept: Vector<4, T>{ZeroInit} {}
/** @copydoc Vector::Vector(ZeroInitT) */
constexpr /*implicit*/ Vector4(ZeroInitT = ZeroInit) noexcept
constexpr explicit Vector4(ZeroInitT) noexcept
/** @todoc remove workaround when doxygen is sane */
#ifndef DOXYGEN_GENERATING_OUTPUT
: Vector<4, T>{ZeroInit}

Loading…
Cancel
Save