@@ -102,18 +102,18 @@ class StringMapImpl {
102102 return reinterpret_cast <StringMapEntryBase *>(TombstoneIntVal);
103103 }
104104
105- unsigned getNumBuckets () const { return NumBuckets; }
106- unsigned getNumItems () const { return NumItems; }
105+ [[nodiscard]] unsigned getNumBuckets () const { return NumBuckets; }
106+ [[nodiscard]] unsigned getNumItems () const { return NumItems; }
107107
108- bool empty () const { return NumItems == 0 ; }
109- unsigned size () const { return NumItems; }
108+ [[nodiscard]] bool empty () const { return NumItems == 0 ; }
109+ [[nodiscard]] unsigned size () const { return NumItems; }
110110
111111 // / Returns the hash value that will be used for the given string.
112112 // / This allows precomputing the value and passing it explicitly
113113 // / to some of the functions.
114114 // / The implementation of this function is not guaranteed to be stable
115115 // / and may change.
116- LLVM_ABI static uint32_t hash (StringRef Key);
116+ [[nodiscard]] LLVM_ABI static uint32_t hash (StringRef Key);
117117
118118 void swap (StringMapImpl &Other) {
119119 std::swap (TheTable, Other.TheTable );
@@ -220,30 +220,35 @@ class LLVM_ALLOCATORHOLDER_EMPTYBASE StringMap
220220 using const_iterator = StringMapIterBase<ValueTy, true >;
221221 using iterator = StringMapIterBase<ValueTy, false >;
222222
223- iterator begin () { return iterator (TheTable, NumBuckets != 0 ); }
224- iterator end () { return iterator (TheTable + NumBuckets); }
225- const_iterator begin () const {
223+ [[nodiscard]] iterator begin () { return iterator (TheTable, NumBuckets != 0 ); }
224+ [[nodiscard]] iterator end () { return iterator (TheTable + NumBuckets); }
225+ [[nodiscard]] const_iterator begin () const {
226226 return const_iterator (TheTable, NumBuckets != 0 );
227227 }
228- const_iterator end () const { return const_iterator (TheTable + NumBuckets); }
228+ [[nodiscard]] const_iterator end () const {
229+ return const_iterator (TheTable + NumBuckets);
230+ }
229231
230- iterator_range<StringMapKeyIterator<ValueTy>> keys () const {
232+ [[nodiscard]] iterator_range<StringMapKeyIterator<ValueTy>> keys () const {
231233 return make_range (StringMapKeyIterator<ValueTy>(begin ()),
232234 StringMapKeyIterator<ValueTy>(end ()));
233235 }
234236
235- iterator find (StringRef Key) { return find (Key, hash (Key)); }
237+ [[nodiscard]] iterator find (StringRef Key) { return find (Key, hash (Key)); }
236238
237- iterator find (StringRef Key, uint32_t FullHashValue) {
239+ [[nodiscard]] iterator find (StringRef Key, uint32_t FullHashValue) {
238240 int Bucket = FindKey (Key, FullHashValue);
239241 if (Bucket == -1 )
240242 return end ();
241243 return iterator (TheTable + Bucket);
242244 }
243245
244- const_iterator find (StringRef Key) const { return find (Key, hash (Key)); }
246+ [[nodiscard]] const_iterator find (StringRef Key) const {
247+ return find (Key, hash (Key));
248+ }
245249
246- const_iterator find (StringRef Key, uint32_t FullHashValue) const {
250+ [[nodiscard]] const_iterator find (StringRef Key,
251+ uint32_t FullHashValue) const {
247252 int Bucket = FindKey (Key, FullHashValue);
248253 if (Bucket == -1 )
249254 return end ();
@@ -252,7 +257,7 @@ class LLVM_ALLOCATORHOLDER_EMPTYBASE StringMap
252257
253258 // / lookup - Return the entry for the specified key, or a default
254259 // / constructed value if no such entry exists.
255- ValueTy lookup (StringRef Key) const {
260+ [[nodiscard]] ValueTy lookup (StringRef Key) const {
256261 const_iterator Iter = find (Key);
257262 if (Iter != end ())
258263 return Iter->second ;
@@ -261,7 +266,7 @@ class LLVM_ALLOCATORHOLDER_EMPTYBASE StringMap
261266
262267 // / at - Return the entry for the specified key, or abort if no such
263268 // / entry exists.
264- const ValueTy &at (StringRef Val) const {
269+ [[nodiscard]] const ValueTy &at (StringRef Val) const {
265270 auto Iter = this ->find (Val);
266271 assert (Iter != this ->end () && " StringMap::at failed due to a missing key" );
267272 return Iter->second ;
@@ -272,18 +277,22 @@ class LLVM_ALLOCATORHOLDER_EMPTYBASE StringMap
272277 ValueTy &operator [](StringRef Key) { return try_emplace (Key).first ->second ; }
273278
274279 // / contains - Return true if the element is in the map, false otherwise.
275- bool contains (StringRef Key) const { return find (Key) != end (); }
280+ [[nodiscard]] bool contains (StringRef Key) const {
281+ return find (Key) != end ();
282+ }
276283
277284 // / count - Return 1 if the element is in the map, 0 otherwise.
278- size_type count (StringRef Key) const { return contains (Key) ? 1 : 0 ; }
285+ [[nodiscard]] size_type count (StringRef Key) const {
286+ return contains (Key) ? 1 : 0 ;
287+ }
279288
280289 template <typename InputTy>
281- size_type count (const StringMapEntry<InputTy> &MapEntry) const {
290+ [[nodiscard]] size_type count (const StringMapEntry<InputTy> &MapEntry) const {
282291 return count (MapEntry.getKey ());
283292 }
284293
285294 // / equal - check whether both of the containers are equal.
286- bool operator ==(const StringMap &RHS) const {
295+ [[nodiscard]] bool operator ==(const StringMap &RHS) const {
287296 if (size () != RHS.size ())
288297 return false ;
289298
@@ -302,7 +311,9 @@ class LLVM_ALLOCATORHOLDER_EMPTYBASE StringMap
302311 return true ;
303312 }
304313
305- bool operator !=(const StringMap &RHS) const { return !(*this == RHS); }
314+ [[nodiscard]] bool operator !=(const StringMap &RHS) const {
315+ return !(*this == RHS);
316+ }
306317
307318 // / insert - Insert the specified key/value pair into the map. If the key
308319 // / already exists in the map, return false and ignore the request, otherwise
@@ -447,8 +458,12 @@ template <typename ValueTy, bool IsConst> class StringMapIterBase {
447458 AdvancePastEmptyBuckets ();
448459 }
449460
450- reference operator *() const { return *static_cast <value_type *>(*Ptr); }
451- pointer operator ->() const { return static_cast <value_type *>(*Ptr); }
461+ [[nodiscard]] reference operator *() const {
462+ return *static_cast <value_type *>(*Ptr);
463+ }
464+ [[nodiscard]] pointer operator ->() const {
465+ return static_cast <value_type *>(*Ptr);
466+ }
452467
453468 StringMapIterBase &operator ++() { // Preincrement
454469 ++Ptr;
0 commit comments