Skip to content

Conversation

gnusi
Copy link

@gnusi gnusi commented May 24, 2025

This PR fixes compilation of flat_hash_map with move only keys, e.g. the following code won't compile:

absl::flat_hash_map<std::unique_ptr<int>, int> a;
absl::flat_hash_map<std::unique_ptr<int>, int> b;
b = std::move(a); // causes compilation error

The reason is that compiler tries to compile a wrong branch due to some values and if's aren't marked with constexpr.

Copy link

google-cla bot commented May 24, 2025

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.

@gnusi gnusi force-pushed the flat_hash_map_mut_keys branch 2 times, most recently from f2c5776 to e2d31c1 Compare May 24, 2025 20:37
Copy link
Member

@derekmauro derekmauro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a test case like the one in the example to prevent a regression?


emplace(new_slot);
if (is_relocatable) {
if constexpr (kIsRelocatable) {
Copy link
Member

@derekmauro derekmauro May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now producing a warning:

./absl/container/internal/container_memory.h:434:35: error: parameter 'alloc' set but not used [-Werror=unused-but-set-parameter]
  434 |   static auto transfer(Allocator* alloc, slot_type* new_slot,

It seems that whatever analysis GCC is doing doesn't understand constexpr branches.

I'm guessing [[maybe_unused]] will fix this. Or perhaps kIsRelocatable could be a bool and the std::conjunction should use ::value instead of ::type(), maybe that would also give GCC a hint?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me try, I'm going to also add a test case as requested.

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.

3 participants