<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/73664>73664</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`vector<int*const>` fail to build with an error in C++20 mode
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ilya-biryukov
</td>
</tr>
</table>
<pre>
This code should technically be allowed per C++20 standard (`int *const` meets the requirement of [MoveInsertable](https://en.cppreference.com/w/cpp/named_req/MoveInsertable) and [Erasable](https://en.cppreference.com/w/cpp/named_req/Erasable)):
```cpp
#include <vector>
int main() {
std::vector<int* const> foo;
foo.push_back(nullptr);
}
```
However, when I build with `clang++ -std=c++20` using libc++ from close to head, I get a compiler error:
```
../include/c++/v1/__algorithm/move.h:42:17: error: cannot assign to return value because function 'operator*' returns a const value
42 | *__result = _IterOps<_AlgPolicy>::__iter_move(__first);
...
<source>:5:9: note: in instantiation of member function 'std::vector<const int *const>::push_back' requested here
5 | foo.push_back(nullptr);
```
Compiling with `-std=c++17` produces no errors. I believe this is somehow related to allocators, because specifying `-D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS` and `-D_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION` with `-std=c++20` makes this code compile again.
See [godbolt](https://gcc.godbolt.org/z/4rfx7nqzM) too.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVU2P2zYQ_TXjy2AFibQl--CD_IUa2M0ukiAIehEoamyxoUiFpLzd_PqCkjf70RRogRqCBFOa4Zt5bx6F9-psiNaw2MBiNxNDaK1bK_0kbmrlnoZv9jKrbfO0_twqj9I2hL61g24wkGyNkkLrJ6wJhdb2kRrsyeEW2AbYhqXogzCNcA0CW0KeKhMQWCmt8QHyFDui4DG0hI6-D8pRRyagPSEsNnf2QkfjyQVRa4LFDtiyDa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