[PATCH] D113797: Support: Make VarStreamArrayIterator iterate over const values

Duncan P. N. Exon Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 12 12:30:46 PST 2021


dexonsmith created this revision.
dexonsmith added reviewers: amccarth, zturner, dblaikie.
dexonsmith requested review of this revision.
Herald added a project: LLVM.

VarStreamArrayIterator returns a reference to a just-computed internal
value. Change it to iterate over `const ValueType` to avoid allowing
clients to mutate the internal state.

This enables removal of the non-const `operator*()`, which doesn't match
the expected iterator semantics.

This is an alternative to https://reviews.llvm.org/D113796.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113797

Files:
  llvm/include/llvm/Support/BinaryStreamArray.h
  llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp


Index: llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp
===================================================================
--- llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp
+++ llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp
@@ -373,7 +373,7 @@
     ++Index;
   }
 
-  DbiModuleDescriptor &Descriptor = *Prev;
+  const DbiModuleDescriptor &Descriptor = *Prev;
   P.formatLine("which contains the descriptor for module {0} ({1}).", Index,
                Descriptor.getModuleName());
 }
Index: llvm/include/llvm/Support/BinaryStreamArray.h
===================================================================
--- llvm/include/llvm/Support/BinaryStreamArray.h
+++ llvm/include/llvm/Support/BinaryStreamArray.h
@@ -153,7 +153,7 @@
 template <typename ValueType, typename Extractor>
 class VarStreamArrayIterator
     : public iterator_facade_base<VarStreamArrayIterator<ValueType, Extractor>,
-                                  std::forward_iterator_tag, ValueType> {
+                                  std::forward_iterator_tag, const ValueType> {
   typedef VarStreamArrayIterator<ValueType, Extractor> IterType;
   typedef VarStreamArray<ValueType, Extractor> ArrayType;
 
@@ -197,11 +197,6 @@
     return ThisValue;
   }
 
-  ValueType &operator*() {
-    assert(Array && !HasError);
-    return ThisValue;
-  }
-
   IterType &operator+=(unsigned N) {
     for (unsigned I = 0; I < N; ++I) {
       // We are done with the current record, discard it so that we are


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113797.386923.patch
Type: text/x-patch
Size: 1464 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211112/6057a9c9/attachment.bin>


More information about the llvm-commits mailing list