From 189b9103845f655b3cda1e24092edd74d9ed052b Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Wed, 19 Feb 2020 15:44:38 +0900 Subject: [PATCH 1/4] fix: solve #97 in the naivest way, macros --- toml/comments.hpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/toml/comments.hpp b/toml/comments.hpp index 5d78440..b2e4980 100644 --- a/toml/comments.hpp +++ b/toml/comments.hpp @@ -81,6 +81,54 @@ struct preserve_comments void assign(std::initializer_list ini) {comments.assign(ini);} void assign(size_type n, const std::string& val) {comments.assign(n, val);} + // Related to the issue #97. + // + // It is known that `std::vector::insert` and `std::vector::erase` in + // the standard library implementation included in GCC 4.8.5 takes + // `std::vector::iterator` instead of `std::vector::const_iterator`. + // Because of the const-correctness, we cannot convert a `const_iterator` to + // an `iterator`. It causes compilation error in GCC 4.8.5. +#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +# if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) <= 40805 +# define TOML11_WORKAROUND_GCC_4_8_X_STANDARD_LIBRARY_IMPLEMENTATION +# endif +#endif + +#ifdef TOML11_WORKAROUND_GCC_4_8_X_STANDARD_LIBRARY_IMPLEMENTATION + iterator insert(iterator p, const std::string& x) + { + return comments.insert(p, x); + } + iterator insert(iterator p, std::string&& x) + { + return comments.insert(p, std::move(x)); + } + void insert(iterator p, size_type n, const std::string& x) + { + return comments.insert(p, n, x); + } + template + void insert(iterator p, InputIterator first, InputIterator last) + { + return comments.insert(p, first, last); + } + void insert(iterator p, std::initializer_list ini) + { + return comments.insert(p, ini); + } + + template + iterator emplace(iterator p, Ts&& ... args) + { + return comments.emplace(p, std::forward(args)...); + } + + iterator erase(iterator pos) {return comments.erase(pos);} + iterator erase(iterator first, iterator last) + { + return comments.erase(first, last); + } +#else iterator insert(const_iterator p, const std::string& x) { return comments.insert(p, x); @@ -114,6 +162,7 @@ struct preserve_comments { return comments.erase(first, last); } +#endif void swap(preserve_comments& other) {comments.swap(other.comments);} From 82fec38e3745a6b18b5d71407b5109dac4f624dc Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Wed, 19 Feb 2020 15:46:25 +0900 Subject: [PATCH 2/4] refactor: simplify internally-used function --- toml/value.hpp | 57 +++++++++++++++++++------------------------------- 1 file changed, 22 insertions(+), 35 deletions(-) diff --git a/toml/value.hpp b/toml/value.hpp index 63df1fc..1838524 100644 --- a/toml/value.hpp +++ b/toml/value.hpp @@ -20,11 +20,24 @@ namespace detail { // to show error messages. not recommended for users. -template class T, template class A> -region_base const& get_region(const basic_value&); -template class T, template class A> -void change_region(basic_value&, Region&&); +template +inline region_base const& get_region(const Value& v) +{ + return *(v.region_info_); +} + +template +void change_region(Value& v, Region&& reg) +{ + using region_type = typename std::remove_reference< + typename std::remove_cv::type + >::type; + + std::shared_ptr new_reg = + std::make_shared(std::forward(reg)); + v.region_info_ = new_reg; + return; +} template class T, template class A> @@ -1724,13 +1737,11 @@ class basic_value } // for error messages - template class T, template class A> - friend region_base const& detail::get_region(const basic_value&); + template + friend region_base const& detail::get_region(const Value& v); - template class T, template class A> - friend void detail::change_region(basic_value&, Region&&); + template + friend void detail::change_region(Value& v, Region&& reg); private: @@ -1760,30 +1771,6 @@ using value = basic_value; using array = typename value::array_type; using table = typename value::table_type; -namespace detail -{ -template class T, template class A> -inline region_base const& get_region(const basic_value& v) -{ - return *(v.region_info_); -} - -template class T, template class A> -void change_region(basic_value& v, Region&& reg) -{ - using region_type = typename std::remove_reference< - typename std::remove_cv::type - >::type; - - std::shared_ptr new_reg = - std::make_shared(std::forward(reg)); - v.region_info_ = new_reg; - return; -} -}// detail - template class T, template class A> inline bool operator==(const basic_value& lhs, const basic_value& rhs) From 2265ca41c658d387a3cc4774599ba5a73835e32a Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Wed, 19 Feb 2020 15:47:34 +0900 Subject: [PATCH 3/4] ci: test with gcc 4.8 and 4.9 on CI --- .travis.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.travis.yml b/.travis.yml index b11ac99..8dc71fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,30 @@ dist: trusty matrix: include: + - os: linux + language: cpp + compiler: gcc + env: COMPILER="g++-4.8" CXX_STANDARD=11 + addons: + apt: + sources: + - sourceline: 'ppa:ubuntu-toolchain-r/test' + - sourceline: 'ppa:mhier/libboost-latest' + packages: + - g++-4.8 + - boost1.70 + - os: linux + language: cpp + compiler: gcc + env: COMPILER="g++-4.9" CXX_STANDARD=11 + addons: + apt: + sources: + - sourceline: 'ppa:ubuntu-toolchain-r/test' + - sourceline: 'ppa:mhier/libboost-latest' + packages: + - g++-4.9 + - boost1.70 - os: linux language: cpp compiler: gcc From 5e3ffb70dd316c75d7c1d0ff9717e55030bf314e Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Wed, 19 Feb 2020 17:00:22 +0900 Subject: [PATCH 4/4] fix: check clang macro when checking gcc is used --- toml/comments.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toml/comments.hpp b/toml/comments.hpp index b2e4980..9cf1ad4 100644 --- a/toml/comments.hpp +++ b/toml/comments.hpp @@ -88,7 +88,7 @@ struct preserve_comments // `std::vector::iterator` instead of `std::vector::const_iterator`. // Because of the const-correctness, we cannot convert a `const_iterator` to // an `iterator`. It causes compilation error in GCC 4.8.5. -#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) && !defined(__clang__) # if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) <= 40805 # define TOML11_WORKAROUND_GCC_4_8_X_STANDARD_LIBRARY_IMPLEMENTATION # endif