Skip to content

[Bug]: abseil conditionally defined hash over std::optional #1883

Closed
@matx-nick

Description

@matx-nick

Describe the issue

In https://github.com/abseil/abseil-cpp/blob/master/absl/hash/internal/hash.h#L883-L889 , abseil defines AbslHashValue for absl::optional whenever T is hashable.

Depending on ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE, absl::optional may or may not be a typedef for std::optional.

Downstream code uses absl::flat_hash_map with a key that is a std::optional and the build succeeds on Linux machines and fails on macOS where ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE is true. That is why Google or-tools doesn't build for me, I encountered this issue at https://github.com/google/or-tools/blob/stable/ortools/sat/intervals.cc#L98 .

When defining the hasher for these types, when the macro is set, please also define them for the std:: versions of those types.

Steps to reproduce the problem

There is a problem with producing a minimized example of the real problem right now due to google/or-tools#4642 .

What you can observe is that static_assert of is_hashable<operations_research::sat::Literal> is true, and is_hashable<std::option<int>> is true (due to the std::hash fallback), but is_hashable<std::option<operations_research::sat::Literal>> is false.

What version of Abseil are you using?

https://registry.bazel.build/modules/abseil-cpp/20240722.0.bcr.2

It was pulled in through bazel_dep(name = "or-tools", version = "9.12")

What operating system and version are you using?

macOS Sequoia 15.4.1

What compiler and version are you using?

Apple clang version 17.0.0 (clang-1700.0.13.3)
Target: arm64-apple-darwin24.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

What build system are you using?

bazel 7.5.0

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions