[PATCH] D113796: Support: Make VarStreamArrayIterator::operator*() const-qualified
Duncan P. N. Exon Smith via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 12 12:25:54 PST 2021
dexonsmith created this revision.
dexonsmith added reviewers: dblaikie, amccarth, zturner.
dexonsmith requested review of this revision.
Herald added a project: LLVM.
VarStreamArrayIterator returns a reference to a just-computed internal
value; since it's an iterator over `ValueType`, change `operator*()` to
always return `ValueType&`.
This patch is conservative in case it's useful to `std::move()` out an
extracted value...
But another option is to change it to iterate over `const ValueType`
and always return `const ValueType&`:
... : iterator_facade_base<..., const ValueType>
It only requires a one-line change to ExplainOutputStyle.cpp to get tests
compiling and passing:
- DbiModuleDescriptor &Descriptor = *Prev;
+ const DbiModuleDescriptor &Descriptor = *Prev;
Based on 175d70ee5c2f03f640151488f5f33b7bd9b96f8d, perhaps that would
better match the original intent? @amccarth, @zturner, thoughts?
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D113796
Files:
llvm/include/llvm/Support/BinaryStreamArray.h
Index: llvm/include/llvm/Support/BinaryStreamArray.h
===================================================================
--- llvm/include/llvm/Support/BinaryStreamArray.h
+++ llvm/include/llvm/Support/BinaryStreamArray.h
@@ -192,12 +192,7 @@
return false;
}
- const ValueType &operator*() const {
- assert(Array && !HasError);
- return ThisValue;
- }
-
- ValueType &operator*() {
+ ValueType &operator*() const {
assert(Array && !HasError);
return ThisValue;
}
@@ -242,7 +237,7 @@
*HadError = true;
}
- ValueType ThisValue;
+ mutable ValueType ThisValue;
BinaryStreamRef IterRef;
Extractor Extract;
const ArrayType *Array{nullptr};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113796.386917.patch
Type: text/x-patch
Size: 688 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211112/79e78de2/attachment.bin>
More information about the llvm-commits
mailing list