Skip to content

Commit e2cfdf7

Browse files
authored
[libc++] Fix vector<const T> (#80711)
#80558 introduced code that assumed that the element type of `vector` is never const. This fixes it and adds a test. Eventually we should remove the `allocator<const T>` extension.
1 parent 6ce03ff commit e2cfdf7

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

libcxx/include/__memory/uninitialized_algorithms.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ __uninitialized_allocator_relocate(_Alloc& __alloc, _Tp* __first, _Tp* __last, _
643643
__guard.__complete();
644644
std::__allocator_destroy(__alloc, __first, __last);
645645
} else {
646-
__builtin_memcpy(__result, __first, sizeof(_Tp) * (__last - __first));
646+
__builtin_memcpy(const_cast<__remove_const_t<_Tp>*>(__result), __first, sizeof(_Tp) * (__last - __first));
647647
}
648648
}
649649

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// Make sure that `vector<const T>` works
10+
11+
#include <vector>
12+
13+
void test() {
14+
std::vector<const int> v;
15+
v.emplace_back(1);
16+
v.push_back(1);
17+
v.resize(3);
18+
}

0 commit comments

Comments
 (0)