Skip to content

Fix flat_hash_map copyability for move-only mapped types - #2179

Open
tachyon29 wants to merge 2 commits into
abseil:masterfrom
tachyon29:fix/1862-copy-constructible
Open

tachyon29 wants to merge 2 commits into
abseil:masterfrom
tachyon29:fix/1862-copy-constructible

Conversation

@tachyon29

Copy link
Copy Markdown

Fixes #1862

absl::flat_hash_map incorrectly reports itself as copy-constructible when the mapped type is not copy-constructible.

For example, flat_hash_map<std::string, std::unique_ptr<int>> reports std::is_copy_constructible_v as true, even though copying the map is ill-formed because std::unique_ptr cannot be copied.

The fix makes the copy constructor and copy assignment of raw_hash_set conditional on the underlying value type being copyable. The hash map/set wrappers also explicitly define their copy/move operations so that base-class constructors cannot bypass these checks.

Tests passed, including the full test suite and ASan/UBSan container tests.

@google-cla

google-cla Bot commented Sep 30, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@tachyon29

Copy link
Copy Markdown
Author

Could a maintainer please approve the workflows for this PR so the GitHub Actions can run? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: flat_hash_map incorrectly reports copyability

1 participant