From 71b865ae6bd6c04e9137603abb818a2b1fd6339c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 23 Jan 2018 12:15:12 +0000 Subject: [PATCH] GCC compatibility changes --- library.properties | 2 +- src/array_wrapper.h | 27 ++++++++++++++------------- src/container.h | 14 +++++++------- src/platform.h | 1 + src/profiles/gcc_generic.h | 9 +++++++-- src/profiles/gcc_linux_x86.h | 9 +++++++-- src/profiles/gcc_windows_x86.h | 9 +++++++-- support/Release notes.txt | 4 ++++ test/test_array_wrapper.cpp | 26 +++++++++++++------------- 9 files changed, 61 insertions(+), 40 deletions(-) diff --git a/library.properties b/library.properties index 67d5914d..feff42fd 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=10.11.0 +version=10.11.1 author= John Wellbelove maintainer=John Wellbelove sentence=A C++ template library tailored for embedded systems. diff --git a/src/array_wrapper.h b/src/array_wrapper.h index 9ada074e..ba839c38 100644 --- a/src/array_wrapper.h +++ b/src/array_wrapper.h @@ -114,7 +114,7 @@ namespace etl //************************************************************************* /// Returns a reference to the first element. //************************************************************************* - ETL_CONSTEXPR reference front() + reference front() { return *&ARRAY_[FRONT]; } @@ -130,7 +130,7 @@ namespace etl //************************************************************************* /// Returns a reference to the last element. //************************************************************************* - ETL_CONSTEXPR reference back() + reference back() { return *&ARRAY_[BACK]; } @@ -146,7 +146,7 @@ namespace etl //************************************************************************* /// Returns a pointer to the first element of the internal storage. //************************************************************************* - ETL_CONSTEXPR pointer data() + pointer data() { return &ARRAY_[BEGIN]; } @@ -162,7 +162,7 @@ namespace etl //************************************************************************* /// Returns an iterator to the beginning of the array. //************************************************************************* - ETL_CONSTEXPR iterator begin() + iterator begin() { return &ARRAY_[BEGIN]; } @@ -186,7 +186,7 @@ namespace etl //************************************************************************* /// Returns an iterator to the end of the array. //************************************************************************* - ETL_CONSTEXPR iterator end() + iterator end() { return &ARRAY_[END]; } @@ -210,7 +210,7 @@ namespace etl //************************************************************************* // Returns an reverse iterator to the reverse beginning of the array. //************************************************************************* - ETL_CONSTEXPR reverse_iterator rbegin() + reverse_iterator rbegin() { return reverse_iterator(&ARRAY_[END]); } @@ -234,7 +234,7 @@ namespace etl //************************************************************************* /// Returns a reverse iterator to the end of the array. //************************************************************************* - ETL_CONSTEXPR reverse_iterator rend() + reverse_iterator rend() { return reverse_iterator(&ARRAY_[BEGIN]); } @@ -274,7 +274,7 @@ namespace etl //************************************************************************* /// Returns a reference to the indexed value. //************************************************************************* - ETL_CONSTEXPR reference operator[](size_t i) + reference operator[](size_t i) { return ARRAY_[i]; } @@ -290,7 +290,7 @@ namespace etl //************************************************************************* /// Returns a reference to the indexed value. //************************************************************************* - ETL_CONSTEXPR reference at(size_t i) + reference at(size_t i) { ETL_ASSERT(i < SIZE, ETL_ERROR(etl::array_wrapper_bounds)); return ARRAY_[i]; @@ -299,7 +299,7 @@ namespace etl //************************************************************************* /// Returns a const reference to the indexed value. //************************************************************************* - ETL_CONSTEXPR const_reference at(size_t i) const + const_reference at(size_t i) const { ETL_ASSERT(i < SIZE, ETL_ERROR(etl::array_wrapper_bounds)); return ARRAY_[i]; @@ -316,8 +316,9 @@ namespace etl //************************************************************************* /// Swaps the contents of arrays. //************************************************************************* - template - void swap(etl::array_wrapper& other) + template + typename etl::enable_if::value, void>::type + swap(etl::array_wrapper& other) { for (size_t i = 0; i < SIZE; ++i) { @@ -345,7 +346,7 @@ namespace etl { return !(lhs == rhs); } - + //************************************************************************* /// Less-than for array wrapper. //************************************************************************* diff --git a/src/container.h b/src/container.h index 9ce23b60..5e622566 100644 --- a/src/container.h +++ b/src/container.h @@ -240,13 +240,13 @@ namespace etl { return std::reverse_iterator(&data[0]); } - + //***************************************************************************** /// Get the next iterator. ///\ingroup container //***************************************************************************** template - ETL_CONSTEXPR TIterator next(TIterator iterator, ptrdiff_t n = 1) + TIterator next(TIterator iterator, ptrdiff_t n = 1) { std::advance(iterator, n); return iterator; @@ -257,7 +257,7 @@ namespace etl ///\ingroup container //***************************************************************************** template - ETL_CONSTEXPR TIterator prev(TIterator iterator, ptrdiff_t n = 1) + TIterator prev(TIterator iterator, ptrdiff_t n = 1) { std::advance(iterator, -n); return iterator; @@ -295,11 +295,11 @@ namespace etl char(&array_size(T(&array)[ARRAY_SIZE]))[ARRAY_SIZE]; } -#if ETL_CPP11_SUPPORTED - #define ETL_ARRAY_SIZE(a) (etl::size(a)) -#else +//#if ETL_CPP11_SUPPORTED +// #define ETL_ARRAY_SIZE(a) (etl::size(a)) +//#else #define ETL_ARRAY_SIZE(a) sizeof(etl::array_size(a)) -#endif +//#endif #endif diff --git a/src/platform.h b/src/platform.h index 9c1487fa..e50d4f19 100644 --- a/src/platform.h +++ b/src/platform.h @@ -40,6 +40,7 @@ SOFTWARE. #include "etl_profile.h" + #if ETL_CPP11_SUPPORTED #define ETL_CONSTEXPR constexpr #else diff --git a/src/profiles/gcc_generic.h b/src/profiles/gcc_generic.h index c19609e6..52b05ebf 100644 --- a/src/profiles/gcc_generic.h +++ b/src/profiles/gcc_generic.h @@ -40,8 +40,13 @@ SOFTWARE. #define ETL_TARGET_DEVICE_GENERIC #define ETL_TARGET_OS_NONE #define ETL_COMPILER_GCC -#define ETL_CPP11_SUPPORTED (__cplusplus >= 201103L) -#define ETL_CPP14_SUPPORTED (__cplusplus >= 201402L) +#ifdef __cplusplus + #define ETL_CPP11_SUPPORTED (__cplusplus >= 201103L) + #define ETL_CPP14_SUPPORTED (__cplusplus >= 201402L) +#else + #define ETL_CPP11_SUPPORTED 0 + #define ETL_CPP14_SUPPORTED 0 +#endif #define ETL_NO_NULLPTR_SUPPORT !ETL_CPP11_SUPPORTED #define ETL_NO_LARGE_CHAR_SUPPORT !ETL_CPP11_SUPPORTED #define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED ETL_CPP14_SUPPORTED diff --git a/src/profiles/gcc_linux_x86.h b/src/profiles/gcc_linux_x86.h index fd8af659..3a8ac812 100644 --- a/src/profiles/gcc_linux_x86.h +++ b/src/profiles/gcc_linux_x86.h @@ -40,8 +40,13 @@ SOFTWARE. #define ETL_TARGET_DEVICE_X86 #define ETL_TARGET_OS_LINUX #define ETL_COMPILER_GCC -#define ETL_CPP11_SUPPORTED (__cplusplus >= 201103L) -#define ETL_CPP14_SUPPORTED (__cplusplus >= 201402L) +#ifdef __cplusplus + #define ETL_CPP11_SUPPORTED (__cplusplus >= 201103L) + #define ETL_CPP14_SUPPORTED (__cplusplus >= 201402L) +#else + #define ETL_CPP11_SUPPORTED 0 + #define ETL_CPP14_SUPPORTED 0 +#endif #define ETL_NO_NULLPTR_SUPPORT !ETL_CPP11_SUPPORTED #define ETL_NO_LARGE_CHAR_SUPPORT !ETL_CPP11_SUPPORTED #define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED ETL_CPP14_SUPPORTED diff --git a/src/profiles/gcc_windows_x86.h b/src/profiles/gcc_windows_x86.h index d60fd198..a234552d 100644 --- a/src/profiles/gcc_windows_x86.h +++ b/src/profiles/gcc_windows_x86.h @@ -40,8 +40,13 @@ SOFTWARE. #define ETL_TARGET_DEVICE_X86 #define ETL_TARGET_OS_WINDOWS #define ETL_COMPILER_GCC -#define ETL_CPP11_SUPPORTED (__cplusplus >= 201103L) -#define ETL_CPP14_SUPPORTED (__cplusplus >= 201402L) +#ifdef __cplusplus + #define ETL_CPP11_SUPPORTED (__cplusplus >= 201103L) + #define ETL_CPP14_SUPPORTED (__cplusplus >= 201402L) +#else + #define ETL_CPP11_SUPPORTED 0 + #define ETL_CPP14_SUPPORTED 0 +#endif #define ETL_NO_NULLPTR_SUPPORT !ETL_CPP11_SUPPORTED #define ETL_NO_LARGE_CHAR_SUPPORT !ETL_CPP11_SUPPORTED #define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED ETL_CPP14_SUPPORTED diff --git a/support/Release notes.txt b/support/Release notes.txt index 54c6643e..8f8941bf 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,4 +1,8 @@ =============================================================================== +10.11.1 +GCC compatibility changes. +=============================================================================== +10.11.0 Added ETL_CONSTEXPR macro and applied to various functions. Allows C++11 and above compilers to set functions as constexpr. diff --git a/test/test_array_wrapper.cpp b/test/test_array_wrapper.cpp index 8d798b67..b4eafaaf 100644 --- a/test/test_array_wrapper.cpp +++ b/test/test_array_wrapper.cpp @@ -84,7 +84,7 @@ namespace //************************************************************************* TEST(test_indexes) { - CHECK_EQUAL(5, Data5::SIZE); + CHECK_EQUAL(5 , Data5::SIZE); CHECK_EQUAL(Data5::SIZE, Data5::MAX_SIZE); CHECK_EQUAL(0, Data5::FRONT); CHECK_EQUAL(Data5::SIZE - 1, Data5::BACK); @@ -357,32 +357,32 @@ namespace TEST(test_size) { Data5 aw5; - CHECK_EQUAL(5, aw5.SIZE); - CHECK_EQUAL(5, aw5.size()); + CHECK_EQUAL(5 , aw5.SIZE); + CHECK_EQUAL(5U, aw5.size()); const Data5 caw5a; - CHECK_EQUAL(5, caw5a.SIZE); - CHECK_EQUAL(5, caw5a.size()); + CHECK_EQUAL(5 , caw5a.SIZE); + CHECK_EQUAL(5U, caw5a.size()); CData5 caw5b; - CHECK_EQUAL(5, caw5b.SIZE); - CHECK_EQUAL(5, caw5b.size()); + CHECK_EQUAL(5 , caw5b.SIZE); + CHECK_EQUAL(5U, caw5b.size()); } //************************************************************************* TEST(test_max_size) { Data5 aw5; - CHECK_EQUAL(5, aw5.MAX_SIZE); - CHECK_EQUAL(5, aw5.max_size()); + CHECK_EQUAL(5 , aw5.MAX_SIZE); + CHECK_EQUAL(5U, aw5.max_size()); const Data5 caw5a; - CHECK_EQUAL(5, caw5a.MAX_SIZE); - CHECK_EQUAL(5, caw5a.max_size()); + CHECK_EQUAL(5 , caw5a.MAX_SIZE); + CHECK_EQUAL(5U, caw5a.max_size()); CData5 caw5b; - CHECK_EQUAL(5, caw5b.MAX_SIZE); - CHECK_EQUAL(5, caw5b.max_size()); + CHECK_EQUAL(5 , caw5b.MAX_SIZE); + CHECK_EQUAL(5U, caw5b.max_size()); } //*************************************************************************