From 637e5aa468ab0c3b1faa3b7970ad3e91fb6c6f74 Mon Sep 17 00:00:00 2001 From: Konstantin Varlamov Date: Mon, 9 Jul 2018 13:56:06 -0400 Subject: C++: for immutable data structures, forbid ignoring result of insert/erase --- Firestore/core/src/firebase/firestore/immutable/CMakeLists.txt | 1 + Firestore/core/src/firebase/firestore/immutable/sorted_map.h | 5 +++-- Firestore/core/src/firebase/firestore/immutable/sorted_set.h | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Firestore/core/src/firebase/firestore/immutable/CMakeLists.txt b/Firestore/core/src/firebase/firestore/immutable/CMakeLists.txt index af97b62..207863e 100644 --- a/Firestore/core/src/firebase/firestore/immutable/CMakeLists.txt +++ b/Firestore/core/src/firebase/firestore/immutable/CMakeLists.txt @@ -27,5 +27,6 @@ cc_library( sorted_set.h tree_sorted_map.h DEPENDS + absl_base firebase_firestore_util ) diff --git a/Firestore/core/src/firebase/firestore/immutable/sorted_map.h b/Firestore/core/src/firebase/firestore/immutable/sorted_map.h index 3a50020..21dcfd4 100644 --- a/Firestore/core/src/firebase/firestore/immutable/sorted_map.h +++ b/Firestore/core/src/firebase/firestore/immutable/sorted_map.h @@ -25,6 +25,7 @@ #include "Firestore/core/src/firebase/firestore/immutable/sorted_map_iterator.h" #include "Firestore/core/src/firebase/firestore/immutable/tree_sorted_map.h" #include "Firestore/core/src/firebase/firestore/util/comparison.h" +#include "absl/base/attributes.h" namespace firebase { namespace firestore { @@ -166,7 +167,7 @@ class SortedMap : public impl::SortedMapBase { * @param value The value to associate with the key. * @return A new dictionary with the added/updated value. */ - SortedMap insert(const K& key, const V& value) const { + ABSL_MUST_USE_RESULT SortedMap insert(const K& key, const V& value) const { switch (tag_) { case Tag::Array: if (array_.size() >= kFixedSize) { @@ -193,7 +194,7 @@ class SortedMap : public impl::SortedMapBase { * @param key The key to remove. * @return A new map without that value. */ - SortedMap erase(const K& key) const { + ABSL_MUST_USE_RESULT SortedMap erase(const K& key) const { switch (tag_) { case Tag::Array: return SortedMap{array_.erase(key)}; diff --git a/Firestore/core/src/firebase/firestore/immutable/sorted_set.h b/Firestore/core/src/firebase/firestore/immutable/sorted_set.h index 1fe91bd..e4d340a 100644 --- a/Firestore/core/src/firebase/firestore/immutable/sorted_set.h +++ b/Firestore/core/src/firebase/firestore/immutable/sorted_set.h @@ -25,6 +25,7 @@ #include "Firestore/core/src/firebase/firestore/util/comparison.h" #include "Firestore/core/src/firebase/firestore/util/hard_assert.h" #include "Firestore/core/src/firebase/firestore/util/hashing.h" +#include "absl/base/attributes.h" namespace firebase { namespace firestore { @@ -76,11 +77,11 @@ class SortedSet { return map_.size(); } - SortedSet insert(const K& key) const { + ABSL_MUST_USE_RESULT SortedSet insert(const K& key) const { return SortedSet{map_.insert(key, {})}; } - SortedSet erase(const K& key) const { + ABSL_MUST_USE_RESULT SortedSet erase(const K& key) const { return SortedSet{map_.erase(key)}; } -- cgit v1.2.3