From 9f464839510a2779b9418ffbc2303a31f155e851 Mon Sep 17 00:00:00 2001 From: Julian Kent Date: Mon, 4 Nov 2019 10:25:21 +0100 Subject: [PATCH] Fix GCC-4.8 bug --- matrix/Matrix.hpp | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/matrix/Matrix.hpp b/matrix/Matrix.hpp index ff1f0541cc86..1954934ffdd6 100644 --- a/matrix/Matrix.hpp +++ b/matrix/Matrix.hpp @@ -18,6 +18,14 @@ #include "math.hpp" +// There is a bug in GCC 4.8, which causes the compiler to segfault due to array {} constructors. +// Do for-loop constructors just for GCC 4.8 +#ifdef __GNUC__ +#define MATRIX_GCC_4_8_WORKAROUND (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 9)) +#else +#define MATRIX_GCC_4_8_WORKAROUND 0 +#endif + namespace matrix { @@ -33,24 +41,27 @@ class Slice; template class Matrix { - +#if MATRIX_GCC_4_8_WORKAROUND Type _data[M][N]; +#else + Type _data[M][N] {}; +#endif public: // Constructors +#if MATRIX_GCC_4_8_WORKAROUND Matrix() { -#ifdef __STDC_IEC_559__ - memset(_data, 0, sizeof(_data)); //workaround for GCC 4.8 bug, don't use {} for array init -#else for (size_t i = 0; i < M; i++) { for (size_t j = 0; j < N; j++) { _data[i][j] = Type{}; } } -#endif } +#else + Matrix() = default; +#endif explicit Matrix(const Type data_[M*N]) { @@ -304,17 +315,7 @@ class Matrix bool operator==(const Matrix &other) const { - const Matrix &self = *this; - - for (size_t i = 0; i < M; i++) { - for (size_t j = 0; j < N; j++) { - if (!isEqualF(self(i, j), other(i, j))) { - return false; - } - } - } - - return true; + return isEqual(*this, other); } bool operator!=(const Matrix &other) const