From 6282b28b6fe218390b843a8a71bb5cc2b63dd05c Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Tue, 11 Jul 2017 15:32:51 +0300 Subject: [core] Added MBGL_CONSTEXPR to satisfy GCC 4.9 --- include/mbgl/map/mode.hpp | 11 ++++++----- include/mbgl/util/convert.hpp | 4 +++- include/mbgl/util/util.hpp | 7 +++++++ src/mbgl/gl/gl.cpp | 3 ++- src/mbgl/map/update.hpp | 7 ++++--- src/mbgl/renderer/render_pass.hpp | 7 ++++--- src/mbgl/text/glyph.hpp | 11 ++++++----- 7 files changed, 32 insertions(+), 18 deletions(-) diff --git a/include/mbgl/map/mode.hpp b/include/mbgl/map/mode.hpp index afec5c0a08..05de2df22c 100644 --- a/include/mbgl/map/mode.hpp +++ b/include/mbgl/map/mode.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -51,23 +52,23 @@ enum class MapDebugOptions : EnumType { #endif // MBGL_USE_GLES2 }; -constexpr MapDebugOptions operator|(MapDebugOptions lhs, MapDebugOptions rhs) { +MBGL_CONSTEXPR MapDebugOptions operator|(MapDebugOptions lhs, MapDebugOptions rhs) { return MapDebugOptions(mbgl::underlying_type(lhs) | mbgl::underlying_type(rhs)); } -constexpr MapDebugOptions& operator|=(MapDebugOptions& lhs, MapDebugOptions rhs) { +MBGL_CONSTEXPR MapDebugOptions& operator|=(MapDebugOptions& lhs, MapDebugOptions rhs) { return (lhs = MapDebugOptions(mbgl::underlying_type(lhs) | mbgl::underlying_type(rhs))); } -constexpr bool operator&(MapDebugOptions lhs, MapDebugOptions rhs) { +MBGL_CONSTEXPR bool operator&(MapDebugOptions lhs, MapDebugOptions rhs) { return mbgl::underlying_type(lhs) & mbgl::underlying_type(rhs); } -constexpr MapDebugOptions& operator&=(MapDebugOptions& lhs, MapDebugOptions rhs) { +MBGL_CONSTEXPR MapDebugOptions& operator&=(MapDebugOptions& lhs, MapDebugOptions rhs) { return (lhs = MapDebugOptions(mbgl::underlying_type(lhs) & mbgl::underlying_type(rhs))); } -constexpr MapDebugOptions operator~(MapDebugOptions value) { +MBGL_CONSTEXPR MapDebugOptions operator~(MapDebugOptions value) { return MapDebugOptions(~mbgl::underlying_type(value)); } diff --git a/include/mbgl/util/convert.hpp b/include/mbgl/util/convert.hpp index c2b3d9950d..bedb1a4a08 100644 --- a/include/mbgl/util/convert.hpp +++ b/include/mbgl/util/convert.hpp @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -7,7 +9,7 @@ namespace util { template::value>> -constexpr std::array convert(const std::array&from) { +MBGL_CONSTEXPR std::array convert(const std::array&from) { std::array to {}; std::copy(std::begin(from), std::end(from), std::begin(to)); return to; diff --git a/include/mbgl/util/util.hpp b/include/mbgl/util/util.hpp index c5a7cb3780..7960b40299 100644 --- a/include/mbgl/util/util.hpp +++ b/include/mbgl/util/util.hpp @@ -12,3 +12,10 @@ #define MBGL_VERIFY_THREAD(tid) #endif + +// GCC 4.9 compatibility +#if !defined(__GNUC__) || __GNUC__ >= 5 +#define MBGL_CONSTEXPR constexpr +#else +#define MBGL_CONSTEXPR inline +#endif diff --git a/src/mbgl/gl/gl.cpp b/src/mbgl/gl/gl.cpp index 8999468dbd..bd6d7b192d 100644 --- a/src/mbgl/gl/gl.cpp +++ b/src/mbgl/gl/gl.cpp @@ -1,12 +1,13 @@ #include #include +#include namespace mbgl { namespace gl { namespace { -constexpr const char* stringFromError(GLenum err) { +MBGL_CONSTEXPR const char* stringFromError(GLenum err) { switch (err) { case GL_INVALID_ENUM: return "GL_INVALID_ENUM"; diff --git a/src/mbgl/map/update.hpp b/src/mbgl/map/update.hpp index 82d98284f5..ab8b10c651 100644 --- a/src/mbgl/map/update.hpp +++ b/src/mbgl/map/update.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include namespace mbgl { @@ -11,15 +12,15 @@ enum class Update { AnnotationData = 1 << 7 }; -constexpr Update operator|(Update lhs, Update rhs) { +MBGL_CONSTEXPR Update operator|(Update lhs, Update rhs) { return Update(mbgl::underlying_type(lhs) | mbgl::underlying_type(rhs)); } -constexpr Update& operator|=(Update& lhs, const Update& rhs) { +MBGL_CONSTEXPR Update& operator|=(Update& lhs, const Update& rhs) { return (lhs = lhs | rhs); } -constexpr bool operator& (Update lhs, Update rhs) { +MBGL_CONSTEXPR bool operator& (Update lhs, Update rhs) { return mbgl::underlying_type(lhs) & mbgl::underlying_type(rhs); } diff --git a/src/mbgl/renderer/render_pass.hpp b/src/mbgl/renderer/render_pass.hpp index d273e34ff7..ae2b923ba1 100644 --- a/src/mbgl/renderer/render_pass.hpp +++ b/src/mbgl/renderer/render_pass.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include @@ -12,15 +13,15 @@ enum class RenderPass : uint8_t { Translucent = 1 << 1, }; -constexpr RenderPass operator|(RenderPass a, RenderPass b) { +MBGL_CONSTEXPR RenderPass operator|(RenderPass a, RenderPass b) { return RenderPass(mbgl::underlying_type(a) | mbgl::underlying_type(b)); } -constexpr RenderPass& operator|=(RenderPass& a, RenderPass b) { +MBGL_CONSTEXPR RenderPass& operator|=(RenderPass& a, RenderPass b) { return (a = a | b); } -constexpr RenderPass operator&(RenderPass a, RenderPass b) { +MBGL_CONSTEXPR RenderPass operator&(RenderPass a, RenderPass b) { return RenderPass(mbgl::underlying_type(a) & mbgl::underlying_type(b)); } diff --git a/src/mbgl/text/glyph.hpp b/src/mbgl/text/glyph.hpp index b9eaedd302..19ecdfd17c 100644 --- a/src/mbgl/text/glyph.hpp +++ b/src/mbgl/text/glyph.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -89,23 +90,23 @@ enum class WritingModeType : uint8_t { Vertical = 1 << 1, }; -constexpr WritingModeType operator|(WritingModeType a, WritingModeType b) { +MBGL_CONSTEXPR WritingModeType operator|(WritingModeType a, WritingModeType b) { return WritingModeType(mbgl::underlying_type(a) | mbgl::underlying_type(b)); } -constexpr WritingModeType& operator|=(WritingModeType& a, WritingModeType b) { +MBGL_CONSTEXPR WritingModeType& operator|=(WritingModeType& a, WritingModeType b) { return (a = a | b); } -constexpr bool operator&(WritingModeType lhs, WritingModeType rhs) { +MBGL_CONSTEXPR bool operator&(WritingModeType lhs, WritingModeType rhs) { return mbgl::underlying_type(lhs) & mbgl::underlying_type(rhs); } -constexpr WritingModeType& operator&=(WritingModeType& lhs, WritingModeType rhs) { +MBGL_CONSTEXPR WritingModeType& operator&=(WritingModeType& lhs, WritingModeType rhs) { return (lhs = WritingModeType(mbgl::underlying_type(lhs) & mbgl::underlying_type(rhs))); } -constexpr WritingModeType operator~(WritingModeType value) { +MBGL_CONSTEXPR WritingModeType operator~(WritingModeType value) { return WritingModeType(~mbgl::underlying_type(value)); } -- cgit v1.2.1