From cb7a0f6404372f866b5c0513d5aaa3b18000dda6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 17 Mar 2013 20:45:06 +0100 Subject: [PATCH] GCC 4.5 compatibility: can't list-initialize array of classes. Awesome bug. In GCC 4.6 it throws plenty of ungoogleable `-pedantic` warnings and in GCC 4.5 it fails directly with "error: bad array initializer". Fallback to initialization using for-cycle. Worked around that in 4.6 by disabling `-pedantic` warnings, must be done this way on 4.5 & 4.4. Hopefully the performance won't be harmed too much. --- src/CMakeLists.txt | 2 +- src/Math/RectangularMatrix.h | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c5c733f48..20e045fc9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,7 +25,7 @@ # Disable `-pedantic` for GCC 4.6, as the compiler doesn't like # list-initialization of array of classes (RectangularMatrix constructors). It # is perfectly legal C++11 and both GCC 4.7 and Clang accept it without notice. -if(CORRADE_GCC46_COMPATIBILITY) +if(CORRADE_GCC46_COMPATIBILITY AND NOT CORRADE_GCC45_COMPATIBILITY) string(REPLACE "-pedantic" "" CORRADE_CXX_FLAGS "${CORRADE_CXX_FLAGS}") endif() diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index fb869992d..b9ab6b7a2 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -106,7 +106,12 @@ template class RectangularMatrix { * * @todo Creating matrix from arbitrary combination of matrices with n rows */ + #ifndef CORRADE_GCC45_COMPATIBILITY template inline constexpr /*implicit*/ RectangularMatrix(const Vector& first, const U&... next): _data{first, next...} { + #else + template inline /*implicit*/ RectangularMatrix(const Vector& first, const U&... next): _data() { + constructInternal({first, next...}); + #endif static_assert(sizeof...(next)+1 == cols, "Improper number of arguments passed to RectangularMatrix constructor"); } @@ -443,7 +448,21 @@ template class RectangularMatrix { private: /* Implementation for RectangularMatrix::RectangularMatrix(const RectangularMatrix&) */ + #ifndef CORRADE_GCC45_COMPATIBILITY template inline constexpr explicit RectangularMatrix(Implementation::Sequence, const RectangularMatrix& matrix): _data{Vector(matrix[sequence])...} {} + #else + template inline explicit RectangularMatrix(Implementation::Sequence, const RectangularMatrix& matrix): _data() { + constructInternal({Vector(matrix[sequence])...}); + } + #endif + + #ifdef CORRADE_GCC45_COMPATIBILITY + /* GCC < 4.6 workaround for "error: bad array initializer" */ + inline void constructInternal(std::initializer_list> data) { + for(std::size_t i = 0; i != data.size(); ++i) + _data[i] = *(data.begin() + i); + } + #endif Vector _data[cols]; };