[PATCH] D28726: Adding const overload of operator* for DenseSet iterators

Hugo Puhlmann via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 13 23:19:11 PST 2017


hstefan created this revision.
hstefan added reviewers: bkramer, jlebar.
hstefan added a subscriber: llvm-commits.

This fixes some problems when building ClangDiagnostics.cpp on Visual Studio 2017 RC. As far as I understand, there was a change in the implementation of the constructor for std::vector with two iterator parameters, which in our case causes an attempt to dereference const Iterator objects. Since there was no overload for a const Iterator, the compile would fail.


https://reviews.llvm.org/D28726

Files:
  include/llvm/ADT/DenseSet.h


Index: include/llvm/ADT/DenseSet.h
===================================================================
--- include/llvm/ADT/DenseSet.h
+++ include/llvm/ADT/DenseSet.h
@@ -104,6 +104,7 @@
     Iterator(const typename MapTy::iterator &i) : I(i) {}
 
     ValueT &operator*() { return I->getFirst(); }
+    const ValueT &operator*() const { return I->getFirst(); }
     ValueT *operator->() { return &I->getFirst(); }
 
     Iterator& operator++() { ++I; return *this; }
@@ -125,7 +126,7 @@
 
     ConstIterator(const typename MapTy::const_iterator &i) : I(i) {}
 
-    const ValueT &operator*() { return I->getFirst(); }
+    const ValueT &operator*() const { return I->getFirst(); }
     const ValueT *operator->() { return &I->getFirst(); }
 
     ConstIterator& operator++() { ++I; return *this; }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28726.84435.patch
Type: text/x-patch
Size: 799 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170114/8e83ff3a/attachment.bin>


More information about the llvm-commits mailing list