<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/119084>119084</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[llvm] Input iterators should not const-overload `operator*` with varying return types
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
StephanTLavavej
</td>
</tr>
</table>
<pre>
The C++ Standard requires that input (and stronger) iterators return the same type when dereferenced, regardless of the top-level constness of the iterator. This is [N4993](https://isocpp.org/files/papers/N4993.pdf) \[iterator.cpp17.general\]/1:
> In the following sections, `a` and `b` denote values of type `X` or `const X`, `difference_type` and `reference` refer to the types `iterator_traits<X>::difference_type` and `iterator_traits<X>::reference`, respectively
followed by \[tab:inputiterator\]:
> Expression: `*a`
> Return type: `reference`, convertible to `T`
In MSVC's STL, we recently merged https://github.com/microsoft/STL/pull/5135, which innocently added top-level constness to an iterator before dereferencing it, and that broke LLVM's build when this iterator was passed to `std::uninitialized_copy`:
https://github.com/llvm/llvm-project/blob/342c8db381129e908116f1059e97d235b62bcaf2/llvm/include/llvm/IR/DebugProgramInstruction.h#L373-L379
LLVM's iterator should not be overloading `const Value *operator*() const` and `Value *operator*()` with a varying return type like this. I searched this directory, and found a very similar occurrence:
https://github.com/llvm/llvm-project/blob/342c8db381129e908116f1059e97d235b62bcaf2/llvm/include/llvm/IR/IntrinsicInst.h#L212-L218
And more potentially affected occurrences:
https://github.com/llvm/llvm-project/blob/342c8db381129e908116f1059e97d235b62bcaf2/llvm/include/llvm/ADT/DenseSet.h#L120-L121
https://github.com/llvm/llvm-project/blob/342c8db381129e908116f1059e97d235b62bcaf2/llvm/include/llvm/ADT/StringExtras.h#L588-L590
https://github.com/llvm/llvm-project/blob/342c8db381129e908116f1059e97d235b62bcaf2/llvm/include/llvm/DebugInfo/PDB/Native/DbiModuleList.h#L46-L47
https://github.com/llvm/llvm-project/blob/342c8db381129e908116f1059e97d235b62bcaf2/llvm/include/llvm/Support/Error.h#L628-L634
https://github.com/llvm/llvm-project/blob/342c8db381129e908116f1059e97d235b62bcaf2/llvm/include/llvm/Support/ManagedStatic.h#L86-L96
I'm probably going to have to revert this specific change of adding top-level constness within MSVC's STL, but I wanted to let you know about these non-conforming LLVM iterators.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVl2P4joS_TXmpQRKHALkgQf6AwmJXl1dWqN5Gzl2JfGMsbO2A8P--lU50M3ufEj3aVpqqUPsHNc5dcpVIgTdWsQ1Kx9Y-TQRQ-ycXx8i9p2wr3txEif8OqmduqxfO4RHxh8Yf4BDFFYJr8DjvwftMUDsRARt-yEC4ythFYTonW3RM16BjuhFdD6Axzh4C7FDCOKIEC89wrlDCwo9NujRSlSMP4LHVnhlMARwTfogun5q8IQGpLMh2rul2wEzeO10AB2AlQ__mldVwconxlddjH1gxYbxLeNbHZzs-5nzLePbRhsMjG970aOnh_TZrFcNRc7KR1Y-vMHLvs-XsxYtemHS2hPj25yQs_RXPMNupNc4Y9xZ2xYCyqidDcSKLTLBFhmQQmyR1fSs0LqIcBJmwJERicIW2WdadZ4eE2OgF1cUpZurWl9o-x3mm4z0Lv2A6EYBLz0G2nLj8yV6oWNgxeNnVjwTi2Lza-DffXV_6Ji90BPtE5rLKM2oByqoL1dVo6hZsUmmuUFfJb2X8_l77zEE7SwrNpDgNyThdfnvq6Eo1HH9_0ORzp7QR10bshDteL1-nm12Fl4Onx4ZXwY4vO5p-xnBo0QbzQWO6FtU8L_uaXXshnom3ZHx7VFL74JrIuPbBLDtB2MY35Z5USa4TssOtLXuiimUQvVTL0cHwr5ZGWpsnMe7uiAv6UiglJBUcbV33xD2-08viUI9aKPGcoqpDm5YZxGgFyGkk0mCENWYuMFqq6MWRv8H1Rfp-guJc0vAb5gbc7r9m_befUVJGtTG1YxvizmXK1UXqzznFVbZKs8XTZ6VFVZLxYuyXvBaioa_42grzaDw_cXub8a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