From dd336120b2ed0644fe253134383828b13b00a3c1 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 22 Mar 2016 16:40:55 -0700 Subject: [PATCH] Fix compilation with GCC 4.9 --- fuzzer/command_file.hpp | 2 +- fuzzer/fuzzer.cpp | 5 +++-- src/collection_notifications.cpp | 4 ++-- src/index_set.cpp | 4 +++- src/index_set.hpp | 10 ++++++++++ src/property.hpp | 18 ++++++++++++++++++ src/results.cpp | 2 +- tests/collection_change_indices.cpp | 6 ++++-- tests/transaction_log_parsing.cpp | 5 +++-- tests/util/index_helpers.hpp | 4 ++-- 10 files changed, 47 insertions(+), 13 deletions(-) diff --git a/fuzzer/command_file.hpp b/fuzzer/command_file.hpp index f06f5433..7de23d43 100644 --- a/fuzzer/command_file.hpp +++ b/fuzzer/command_file.hpp @@ -21,7 +21,7 @@ struct RealmState { realm::Table& table; realm::LinkViewRef lv; - int64_t uid = 0; + int64_t uid; std::vector modified; }; diff --git a/fuzzer/fuzzer.cpp b/fuzzer/fuzzer.cpp index b1c9aebb..e3572769 100644 --- a/fuzzer/fuzzer.cpp +++ b/fuzzer/fuzzer.cpp @@ -97,7 +97,8 @@ static void verify(CollectionChangeIndices const& changes, std::vector // Apply the changes from the transaction log to our copy of the // initial, using UITableView's batching rules (i.e. delete, then // insert, then update) - auto it = std::make_reverse_iterator(changes.deletions.end()), end = std::make_reverse_iterator(changes.deletions.begin()); + auto it = util::make_reverse_iterator(changes.deletions.end()); + auto end = util::make_reverse_iterator(changes.deletions.begin()); for (; it != end; ++it) { values.erase(values.begin() + it->first, values.begin() + it->second); } @@ -207,7 +208,7 @@ int main(int argc, char** argv) { config.in_memory = true; config.automatic_change_notifications = false; - Schema schema = { + Schema schema{ {"object", "", { {"id", PropertyTypeInt}, {"value", PropertyTypeInt} diff --git a/src/collection_notifications.cpp b/src/collection_notifications.cpp index 99c40714..11abf418 100644 --- a/src/collection_notifications.cpp +++ b/src/collection_notifications.cpp @@ -601,8 +601,8 @@ CollectionChangeBuilder CollectionChangeBuilder::calculate(std::vector c #ifdef REALM_DEBUG { // Verify that applying the calculated change to prev_rows actually produces next_rows auto rows = prev_rows; - auto it = std::make_reverse_iterator(ret.deletions.end()); - auto end = std::make_reverse_iterator(ret.deletions.begin()); + auto it = util::make_reverse_iterator(ret.deletions.end()); + auto end = util::make_reverse_iterator(ret.deletions.begin()); for (; it != end; ++it) { rows.erase(rows.begin() + it->first, rows.begin() + it->second); } diff --git a/src/index_set.cpp b/src/index_set.cpp index 68fa6b2c..a9c2d5a0 100644 --- a/src/index_set.cpp +++ b/src/index_set.cpp @@ -20,6 +20,8 @@ #include +#include + using namespace realm; const size_t IndexSet::npos; @@ -138,7 +140,7 @@ void IndexSet::add_shifted_by(IndexSet const& shifted_by, IndexSet const& values copy(old_it, old_end, back_inserter(m_ranges)); } - REALM_ASSERT_DEBUG(std::distance(as_indexes().begin(), as_indexes().end()) == expected); + REALM_ASSERT_DEBUG((size_t)std::distance(as_indexes().begin(), as_indexes().end()) == expected); } void IndexSet::set(size_t len) diff --git a/src/index_set.hpp b/src/index_set.hpp index e58af4b8..944149bc 100644 --- a/src/index_set.hpp +++ b/src/index_set.hpp @@ -155,6 +155,16 @@ private: // Add an index which must be greater than the largest index in the set void add_back(size_t index); }; + +namespace util { +// This was added in C++14 but is missing from libstdc++ 4.9 +template +std::reverse_iterator make_reverse_iterator(Iterator it) +{ + return std::reverse_iterator(it); +} +} // namespace util + } // namespace realm #endif // REALM_INDEX_SET_HPP diff --git a/src/property.hpp b/src/property.hpp index 25a3bda7..7f968bd2 100644 --- a/src/property.hpp +++ b/src/property.hpp @@ -52,6 +52,20 @@ namespace realm { || type == PropertyTypeDate || type == PropertyTypeString; } + +#if __GNUC__ < 5 + // GCC 4.9 does not support C++14 braced-init with NSDMIs + Property(std::string name="", PropertyType type=PropertyTypeInt, std::string object_type="", + bool is_primary=false, bool is_indexed=false, bool is_nullable=false) + : name(std::move(name)) + , type(type) + , object_type(std::move(object_type)) + , is_primary(is_primary) + , is_indexed(is_indexed) + , is_nullable(is_nullable) + { + } +#endif }; static inline const char *string_for_property_type(PropertyType type) { @@ -76,6 +90,10 @@ namespace realm { return "object"; case PropertyTypeArray: return "array"; +#if __GNUC__ + default: + __builtin_unreachable(); +#endif } } } diff --git a/src/results.cpp b/src/results.cpp index 525e4b49..b5048003 100644 --- a/src/results.cpp +++ b/src/results.cpp @@ -293,7 +293,7 @@ util::Optional Results::aggregate(size_t column, bool return_none_for_emp return none; return util::Optional(getter(*m_table)); case Mode::LinkView: - m_query = get_query(); + m_query = this->get_query(); m_mode = Mode::Query; REALM_FALLTHROUGH; case Mode::Query: diff --git a/tests/collection_change_indices.cpp b/tests/collection_change_indices.cpp index d02ed52b..5d67a5e2 100644 --- a/tests/collection_change_indices.cpp +++ b/tests/collection_change_indices.cpp @@ -4,6 +4,8 @@ #include "util/index_helpers.hpp" +#include + using namespace realm; TEST_CASE("[collection_change] insert()") { @@ -230,10 +232,10 @@ TEST_CASE("[collection_change] clear()") { SECTION("sets deletions SIZE_T_MAX if that if the given previous size") { c.insertions = {1, 2, 3}; - c.clear(SIZE_T_MAX); + c.clear(std::numeric_limits::max()); REQUIRE(c.deletions.size() == 1); REQUIRE(c.deletions.begin()->first == 0); - REQUIRE(c.deletions.begin()->second == SIZE_T_MAX); + REQUIRE(c.deletions.begin()->second == std::numeric_limits::max()); } } diff --git a/tests/transaction_log_parsing.cpp b/tests/transaction_log_parsing.cpp index e8c3ae2a..76a20f46 100644 --- a/tests/transaction_log_parsing.cpp +++ b/tests/transaction_log_parsing.cpp @@ -73,7 +73,8 @@ private: // Apply the changes from the transaction log to our copy of the // initial, using UITableView's batching rules (i.e. delete, then // insert, then update) - auto it = std::make_reverse_iterator(info.deletions.end()), end = std::make_reverse_iterator(info.deletions.begin()); + auto it = util::make_reverse_iterator(info.deletions.end()); + auto end = util::make_reverse_iterator(info.deletions.begin()); for (; it != end; ++it) { m_initial.erase(m_initial.begin() + it->first, m_initial.begin() + it->second); } @@ -92,7 +93,7 @@ private: // and make sure we end up with the same end result REQUIRE(m_initial.size() == m_linkview->size()); - for (auto i = 0; i < m_initial.size(); ++i) + for (size_t i = 0; i < m_initial.size(); ++i) CHECK(m_initial[i] == m_linkview->get(i).get_int(0)); // Verify that everything marked as a move actually is one diff --git a/tests/util/index_helpers.hpp b/tests/util/index_helpers.hpp index 4608932d..5ca6803c 100644 --- a/tests/util/index_helpers.hpp +++ b/tests/util/index_helpers.hpp @@ -4,7 +4,7 @@ auto actual = index_set.as_indexes(); \ INFO("Checking " #index_set); \ REQUIRE(expected.size() == std::distance(actual.begin(), actual.end())); \ - auto begin = actual.begin(), end = actual.end(); \ + auto begin = actual.begin(); \ for (auto index : expected) { \ REQUIRE(*begin++ == index); \ } \ @@ -14,7 +14,7 @@ auto actual = (c); \ std::initializer_list expected = {__VA_ARGS__}; \ REQUIRE(expected.size() == actual.moves.size()); \ - auto begin = actual.moves.begin(), end = actual.moves.end(); \ + auto begin = actual.moves.begin(); \ for (auto move : expected) { \ CHECK(begin->from == move.from); \ CHECK(begin->to == move.to); \