From 1b5d3557ecfe5566d8319e13b39a2c6bfa19406a Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 2 Jul 2014 17:54:36 +0000 Subject: [PATCH] build: some compilation fixes and tweaks for older (<= 4.6) versions of GCC. --- configure.ac | 3 +++ src/image/codec/oric-image.cpp | 2 ++ src/lol/base/array.h | 46 +++++++++++++++++++++++++++++----- src/lol/base/features.h | 13 +++++----- src/lol/math/vector.h | 6 ++--- 5 files changed, 55 insertions(+), 15 deletions(-) diff --git a/configure.ac b/configure.ac index a415f18f..d68e309b 100644 --- a/configure.ac +++ b/configure.ac @@ -35,6 +35,9 @@ dnl C++11 mode. Checked early so that we don't run into surprises. LOL_TRY_CXXFLAGS(-std=c++11, [AM_CXXFLAGS="${AM_CXXFLAGS} -std=c++11" CXXFLAGS="${CXXFLAGS} -std=c++11"]) +LOL_TRY_CXXFLAGS(-std=c++0x, + [AM_CXXFLAGS="${AM_CXXFLAGS} -std=c++0x" + CXXFLAGS="${CXXFLAGS} -std=c++0x"]) AC_LANG_PUSH(C++) AC_MSG_CHECKING(for C++11 enum class support) diff --git a/src/image/codec/oric-image.cpp b/src/image/codec/oric-image.cpp index cb4ec8b0..e6f09fb9 100644 --- a/src/image/codec/oric-image.cpp +++ b/src/image/codec/oric-image.cpp @@ -12,6 +12,8 @@ # include "config.h" #endif +#include + #include #include "../../image/image-private.h" diff --git a/src/lol/base/array.h b/src/lol/base/array.h index b455664b..8c7257ba 100644 --- a/src/lol/base/array.h +++ b/src/lol/base/array.h @@ -462,11 +462,6 @@ public: array_base *m_array; }; - ConstIterator begin() const { return ConstIterator(this, 0); } - ConstIterator end() const { return ConstIterator(this, m_count); } - Iterator begin() { return Iterator(this, 0); } - Iterator end() { return Iterator(this, m_count); } - public: inline int Count() const { return m_count; } inline int Bytes() const { return m_count * sizeof(element_t); } @@ -897,11 +892,50 @@ public: #endif }; -/* Transitional alias for the camelcase version of lol::array */ +/* + * C++11 iterators + */ + +template +typename array::Iterator begin(array &a) +{ + return typename array::Iterator(&a, 0); +} + +template +typename array::Iterator end(array &a) +{ + return typename array::Iterator(&a, a.Count()); +} + +template +typename array::ConstIterator begin(array const &a) +{ + return typename array::ConstIterator(&a, 0); +} + +template +typename array::ConstIterator end(array const &a) +{ + return typename array::ConstIterator(&a, a.Count()); +} + +/* + * Transitional alias for the deprecated camelcase version of lol::array + */ + +#if LOL_FEATURE_CXX11_TEMPLATE_ALIASES template using Array = array; +#else +# define Array array +#endif } /* namespace lol */ diff --git a/src/lol/base/features.h b/src/lol/base/features.h index 4289ee86..3e7c770f 100644 --- a/src/lol/base/features.h +++ b/src/lol/base/features.h @@ -45,6 +45,9 @@ #define LOL_FEATURE_CXX11_CONSTEXPR 0 #define LOL_FEATURE_CXX11_ISNAN 0 +/* This one is OK, except on GCC <= 4.6 */ +#define LOL_FEATURE_CXX11_TEMPLATE_ALIASES 1 + #if defined __GNUC__ /* GCC */ # if defined(__GXX_EXPERIMENTAL_CXX0X) || __cplusplus >= 201103L # undef LOL_FEATURE_CXX11_CONSTEXPR @@ -52,6 +55,10 @@ # undef LOL_FEATURE_CXX11_ISNAN # define LOL_FEATURE_CXX11_ISNAN 1 # endif +# if (__GNUC__ * 100 + __GNUC_MINOR__) < 470 +# undef LOL_FEATURE_CXX11_TEMPLATE_ALIASES +# define LOL_FEATURE_CXX11_TEMPLATE_ALIASES 0 +# endif #elif defined __has_feature /* Clang */ # if __has_feature(cxx_constexpr) # undef LOL_FEATURE_CXX11_CONSTEXPR @@ -59,12 +66,6 @@ # endif #endif -#if LOL_FEATURE_CXX11_CONSTEXPR -# define LOL_CONSTEXPR constexpr -#else -# define LOL_CONSTEXPR /* Nothing */ -#endif - /* * Ensure we have nullptr. diff --git a/src/lol/math/vector.h b/src/lol/math/vector.h index eb484a19..50a25c4e 100644 --- a/src/lol/math/vector.h +++ b/src/lol/math/vector.h @@ -375,12 +375,12 @@ template struct Cmplx typedef Cmplx type; inline constexpr Cmplx() {} - inline constexpr Cmplx(T X) : x(X), y(0) {} + inline constexpr Cmplx(T X) : x(X), y(T(0)) {} inline constexpr Cmplx(T X, T Y) : x(X), y(Y) {} template explicit inline constexpr Cmplx(Cmplx const &z) - : Cmplx(z[0], z[1]) {} + : x(z.x), y(z.y) {} LOL_COMMON_MEMBER_OPS(x) LOL_NONVECTOR_MEMBER_OPS() @@ -1136,7 +1136,7 @@ template struct Quat template explicit inline constexpr Quat(Quat const &q) - : Quat(q[0], q[1], q[2], q[3]) {} + : w(q.w), x(q.x), y(q.y), z(q.z) {} Quat(matrix<3,3,T> const &m); Quat(matrix<4,4,T> const &m);