Peter Collingbourne 5b8c175804
[libc++] Add another const_cast to support hash_map copy assignment
There was one more const_cast needed after #183223 without which
copy assignment of hash_map was broken. Add it, together with a copy
assignment test.

Reviewers: ldionne

Pull Request: https://github.com/llvm/llvm-project/pull/188660
2026-03-26 12:12:01 -07:00

32 lines
798 B
C++

//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// ADDITIONAL_COMPILE_FLAGS: -Wno-deprecated -Wno-deprecated-copy
// hash_map::hash_map(const hash_map&)
#include <cassert>
#include <ext/hash_map>
int main(int, char**) {
__gnu_cxx::hash_map<int, int> map;
map.insert(std::make_pair(1, 1));
map.insert(std::make_pair(2, 1));
auto map2 = map;
assert(map2.size() == 2);
map.insert(std::make_pair(3, 1));
map2 = map;
assert(map2.size() == 3);
return 0;
}