From 000d8f81296b0eb926418252c3e87514e55d8fa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 6 Sep 2015 22:53:08 +0200 Subject: [PATCH] MSVC 2015 compatibility: Math external conversion constexpr issues. Caused by inability to delegate constexpr constructors. Subclasses are okay, fortunately. --- src/Magnum/Math/Complex.h | 7 ++++++- src/Magnum/Math/DualComplex.h | 7 ++++++- src/Magnum/Math/DualQuaternion.h | 7 ++++++- src/Magnum/Math/Quaternion.h | 7 ++++++- src/Magnum/Math/Range.h | 7 ++++++- src/Magnum/Math/RectangularMatrix.h | 7 ++++++- src/Magnum/Math/Test/ComplexTest.cpp | 6 ++++-- src/Magnum/Math/Test/DualComplexTest.cpp | 6 ++++-- src/Magnum/Math/Test/DualQuaternionTest.cpp | 6 ++++-- src/Magnum/Math/Test/QuaternionTest.cpp | 6 ++++-- src/Magnum/Math/Test/RangeTest.cpp | 8 +++++--- src/Magnum/Math/Test/RectangularMatrixTest.cpp | 6 ++++-- src/Magnum/Math/Test/VectorTest.cpp | 6 ++++-- src/Magnum/Math/Vector.h | 7 ++++++- 14 files changed, 71 insertions(+), 22 deletions(-) diff --git a/src/Magnum/Math/Complex.h b/src/Magnum/Math/Complex.h index 06644177d..ce898204e 100644 --- a/src/Magnum/Math/Complex.h +++ b/src/Magnum/Math/Complex.h @@ -168,7 +168,12 @@ template class Complex { constexpr explicit Complex(const Vector2& vector): _real(vector.x()), _imaginary(vector.y()) {} /** @brief Construct complex number from external representation */ - template::from(std::declval()))> constexpr explicit Complex(const U& other): Complex{Implementation::ComplexConverter::from(other)} {} + template::from(std::declval()))> + #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 Complex(const U& other): Complex{Implementation::ComplexConverter::from(other)} {} /** @brief Convert complex number to external representation */ template::to(std::declval>()))> constexpr explicit operator U() const { diff --git a/src/Magnum/Math/DualComplex.h b/src/Magnum/Math/DualComplex.h index 12ee6e1fa..7e4084016 100644 --- a/src/Magnum/Math/DualComplex.h +++ b/src/Magnum/Math/DualComplex.h @@ -150,7 +150,12 @@ template class DualComplex: public Dual> { #endif /** @brief Construct dual complex number from external representation */ - template::from(std::declval()))> constexpr explicit DualComplex(const U& other): DualComplex{Implementation::DualComplexConverter::from(other)} {} + template::from(std::declval()))> + #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 DualComplex(const U& other): DualComplex{Implementation::DualComplexConverter::from(other)} {} /** @brief Copy constructor */ constexpr DualComplex(const Dual>& other): Dual>(other) {} diff --git a/src/Magnum/Math/DualQuaternion.h b/src/Magnum/Math/DualQuaternion.h index 2e8b52143..11c0e5953 100644 --- a/src/Magnum/Math/DualQuaternion.h +++ b/src/Magnum/Math/DualQuaternion.h @@ -158,7 +158,12 @@ template class DualQuaternion: public Dual> { #endif /** @brief Construct dual quaternion from external representation */ - template::from(std::declval()))> constexpr explicit DualQuaternion(const U& other): DualQuaternion{Implementation::DualQuaternionConverter::from(other)} {} + template::from(std::declval()))> + #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 DualQuaternion(const U& other): DualQuaternion{Implementation::DualQuaternionConverter::from(other)} {} /** @brief Copy constructor */ constexpr DualQuaternion(const Dual>& other): Dual>(other) {} diff --git a/src/Magnum/Math/Quaternion.h b/src/Magnum/Math/Quaternion.h index c7d828b58..d09eab8c6 100644 --- a/src/Magnum/Math/Quaternion.h +++ b/src/Magnum/Math/Quaternion.h @@ -225,7 +225,12 @@ template class Quaternion { constexpr explicit Quaternion(const Vector3& vector): _vector(vector), _scalar(T(0)) {} /** @brief Construct quaternion from external representation */ - template::from(std::declval()))> constexpr explicit Quaternion(const U& other): Quaternion{Implementation::QuaternionConverter::from(other)} {} + template::from(std::declval()))> + #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 Quaternion(const U& other): Quaternion{Implementation::QuaternionConverter::from(other)} {} /** @brief Convert quaternion to external representation */ template::to(std::declval>()))> constexpr explicit operator U() const { diff --git a/src/Magnum/Math/Range.h b/src/Magnum/Math/Range.h index 9ef651c57..d4a7d9e4c 100644 --- a/src/Magnum/Math/Range.h +++ b/src/Magnum/Math/Range.h @@ -99,7 +99,12 @@ template class Range { template constexpr explicit Range(const Range& other): _min(other._min), _max(other._max) {} /** @brief Construct range from external representation */ - template::from(std::declval()))> constexpr explicit Range(const U& other): Range{Implementation::RangeConverter::from(other)} {} + template::from(std::declval()))> + #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 Range(const U& other): Range{Implementation::RangeConverter::from(other)} {} /** @brief Convert range to external representation */ template::to(std::declval>()))> constexpr explicit operator U() const { diff --git a/src/Magnum/Math/RectangularMatrix.h b/src/Magnum/Math/RectangularMatrix.h index ac875a179..54b31691d 100644 --- a/src/Magnum/Math/RectangularMatrix.h +++ b/src/Magnum/Math/RectangularMatrix.h @@ -165,7 +165,12 @@ template class RectangularMatrix { explicit RectangularMatrix(const RectangularMatrix& other): RectangularMatrix(typename Implementation::GenerateSequence::Type(), other) {} /** @brief Construct matrix from external representation */ - template::from(std::declval()))> constexpr explicit RectangularMatrix(const U& other): RectangularMatrix(Implementation::RectangularMatrixConverter::from(other)) {} + template::from(std::declval()))> + #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 RectangularMatrix(const U& other): RectangularMatrix(Implementation::RectangularMatrixConverter::from(other)) {} /** @brief Copy constructor */ constexpr RectangularMatrix(const RectangularMatrix&) = default; diff --git a/src/Magnum/Math/Test/ComplexTest.cpp b/src/Magnum/Math/Test/ComplexTest.cpp index 55253b8bd..3d53b2c0d 100644 --- a/src/Magnum/Math/Test/ComplexTest.cpp +++ b/src/Magnum/Math/Test/ComplexTest.cpp @@ -187,8 +187,10 @@ void ComplexTest::convert() { /* GCC 5.1 fills the result with zeros instead of properly calling delegated copy constructor if using constexpr. Reported here: - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66450 */ - #if !defined(__GNUC__) || defined(__clang__) + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66450 + MSVC 2015: Can't use delegating constructors with constexpr: + https://connect.microsoft.com/VisualStudio/feedback/details/1579279/c-constexpr-does-not-work-with-delegating-constructors */ + #if (!defined(__GNUC__) || defined(__clang__)) && !defined(CORRADE_MSVC2015_COMPATIBILITY) constexpr #endif Complex c(a); diff --git a/src/Magnum/Math/Test/DualComplexTest.cpp b/src/Magnum/Math/Test/DualComplexTest.cpp index 92e989aad..8e8da9a22 100644 --- a/src/Magnum/Math/Test/DualComplexTest.cpp +++ b/src/Magnum/Math/Test/DualComplexTest.cpp @@ -181,8 +181,10 @@ void DualComplexTest::convert() { /* GCC 5.1 fills the result with zeros instead of properly calling delegated copy constructor if using constexpr. Reported here: - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66450 */ - #if !defined(__GNUC__) || defined(__clang__) + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66450 + MSVC 2015: Can't use delegating constructors with constexpr: + https://connect.microsoft.com/VisualStudio/feedback/details/1579279/c-constexpr-does-not-work-with-delegating-constructors */ + #if (!defined(__GNUC__) || defined(__clang__)) && !defined(CORRADE_MSVC2015_COMPATIBILITY) constexpr #endif DualComplex c{a}; diff --git a/src/Magnum/Math/Test/DualQuaternionTest.cpp b/src/Magnum/Math/Test/DualQuaternionTest.cpp index 7ba8a8062..9c637abf0 100644 --- a/src/Magnum/Math/Test/DualQuaternionTest.cpp +++ b/src/Magnum/Math/Test/DualQuaternionTest.cpp @@ -182,8 +182,10 @@ void DualQuaternionTest::convert() { /* GCC 5.1 fills the result with zeros instead of properly calling delegated copy constructor if using constexpr. Reported here: - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66450 */ - #if !defined(__GNUC__) || defined(__clang__) + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66450 + MSVC 2015: Can't use delegating constructors with constexpr: + https://connect.microsoft.com/VisualStudio/feedback/details/1579279/c-constexpr-does-not-work-with-delegating-constructors */ + #if (!defined(__GNUC__) || defined(__clang__)) && !defined(CORRADE_MSVC2015_COMPATIBILITY) constexpr #endif DualQuaternion c{a}; diff --git a/src/Magnum/Math/Test/QuaternionTest.cpp b/src/Magnum/Math/Test/QuaternionTest.cpp index e5992882c..398efbf04 100644 --- a/src/Magnum/Math/Test/QuaternionTest.cpp +++ b/src/Magnum/Math/Test/QuaternionTest.cpp @@ -188,8 +188,10 @@ void QuaternionTest::convert() { /* GCC 5.1 fills the result with zeros instead of properly calling delegated copy constructor if using constexpr. Reported here: - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66450 */ - #if !defined(__GNUC__) || defined(__clang__) + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66450 + MSVC 2015: Can't use delegating constructors with constexpr: + https://connect.microsoft.com/VisualStudio/feedback/details/1579279/c-constexpr-does-not-work-with-delegating-constructors */ + #if (!defined(__GNUC__) || defined(__clang__)) && !defined(CORRADE_MSVC2015_COMPATIBILITY) constexpr #endif Quaternion c{a}; diff --git a/src/Magnum/Math/Test/RangeTest.cpp b/src/Magnum/Math/Test/RangeTest.cpp index fe310842e..e0565663e 100644 --- a/src/Magnum/Math/Test/RangeTest.cpp +++ b/src/Magnum/Math/Test/RangeTest.cpp @@ -260,12 +260,14 @@ void RangeTest::convert() { /* GCC 5.1 fills the result with zeros instead of properly calling delegated copy constructor if using constexpr. Reported here: - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66450 */ - #if !defined(__GNUC__) || defined(__clang__) + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66450 + MSVC 2015: Can't use delegating constructors with constexpr: + https://connect.microsoft.com/VisualStudio/feedback/details/1579279/c-constexpr-does-not-work-with-delegating-constructors */ + #if (!defined(__GNUC__) || defined(__clang__)) && !defined(CORRADE_MSVC2015_COMPATIBILITY) constexpr #endif Range<2, Float> g{b}; - #if !defined(__GNUC__) || defined(__clang__) + #if (!defined(__GNUC__) || defined(__clang__)) && !defined(CORRADE_MSVC2015_COMPATIBILITY) constexpr #endif Range1D h{a}; diff --git a/src/Magnum/Math/Test/RectangularMatrixTest.cpp b/src/Magnum/Math/Test/RectangularMatrixTest.cpp index dccd1bc5b..5a1c673b6 100644 --- a/src/Magnum/Math/Test/RectangularMatrixTest.cpp +++ b/src/Magnum/Math/Test/RectangularMatrixTest.cpp @@ -237,8 +237,10 @@ void RectangularMatrixTest::convert() { /* GCC 5.1 fills the result with zeros instead of properly calling delegated copy constructor if using constexpr. Reported here: - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66450 */ - #if !defined(__GNUC__) || defined(__clang__) + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66450 + MSVC 2015: Can't use delegating constructors with constexpr: + https://connect.microsoft.com/VisualStudio/feedback/details/1579279/c-constexpr-does-not-work-with-delegating-constructors */ + #if (!defined(__GNUC__) || defined(__clang__)) && !defined(CORRADE_MSVC2015_COMPATIBILITY) constexpr #endif Matrix2x3 c{a}; diff --git a/src/Magnum/Math/Test/VectorTest.cpp b/src/Magnum/Math/Test/VectorTest.cpp index fab671094..7c026b3ec 100644 --- a/src/Magnum/Math/Test/VectorTest.cpp +++ b/src/Magnum/Math/Test/VectorTest.cpp @@ -247,8 +247,10 @@ void VectorTest::convert() { /* GCC 5.1 fills the result with zeros instead of properly calling delegated copy constructor if using constexpr. Reported here: - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66450 */ - #if !defined(__GNUC__) || defined(__clang__) + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66450 + MSVC 2015: Can't use delegating constructors with constexpr: + https://connect.microsoft.com/VisualStudio/feedback/details/1579279/c-constexpr-does-not-work-with-delegating-constructors */ + #if (!defined(__GNUC__) || defined(__clang__)) && !defined(CORRADE_MSVC2015_COMPATIBILITY) constexpr #endif Vector3 c{a}; diff --git a/src/Magnum/Math/Vector.h b/src/Magnum/Math/Vector.h index 83d53df76..0c283de32 100644 --- a/src/Magnum/Math/Vector.h +++ b/src/Magnum/Math/Vector.h @@ -211,7 +211,12 @@ template class Vector { explicit Vector(const Vector& other): Vector(typename Implementation::GenerateSequence::Type(), other) {} /** @brief Construct vector from external representation */ - template::from(std::declval()))> constexpr explicit Vector(const U& other): Vector(Implementation::VectorConverter::from(other)) {} + template::from(std::declval()))> + #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 Vector(const U& other): Vector(Implementation::VectorConverter::from(other)) {} /** @brief Copy constructor */ constexpr Vector(const Vector&) = default;