Skip to content

Commit

Permalink
Fix GCC-4.8 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jkflying authored and dagar committed Nov 4, 2019
1 parent 445f58d commit 9f46483
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions matrix/Matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{

Expand All @@ -33,24 +41,27 @@ class Slice;
template<typename Type, size_t M, size_t N>
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])
{
Expand Down Expand Up @@ -304,17 +315,7 @@ class Matrix

bool operator==(const Matrix<Type, M, N> &other) const
{
const Matrix<Type, M, N> &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<Type, M, N> &other) const
Expand Down

0 comments on commit 9f46483

Please sign in to comment.