Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unordered_map doesn't work with an enum as key in C++11 mode #49601

Closed
mstorsjo opened this issue May 7, 2021 · 4 comments
Closed

unordered_map doesn't work with an enum as key in C++11 mode #49601

mstorsjo opened this issue May 7, 2021 · 4 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla confirmed Verified by a second party libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@mstorsjo
Copy link
Member

mstorsjo commented May 7, 2021

Bugzilla Link 50257
Version unspecified
OS All
CC @mclow

Extended Description

A test snippet like this compiles successfully in C++14 mode but not in C++11 mode:

#include <unordered_map>
enum MyEnum { A, B, C };
std::unordered_map<MyEnum, int> myMap;

In C++11 mode, it fails like this:

In file included from libcxx-unordered-map.cpp:1:
In file included from /home/martin/clang-nightly/x86_64-w64-mingw32/include/c++/v1/unordered_map:435:
In file included from /home/martin/clang-nightly/x86_64-w64-mingw32/include/c++/v1/__hash_table:15:
In file included from /home/martin/clang-nightly/x86_64-w64-mingw32/include/c++/v1/memory:668:
/home/martin/clang-nightly/x86_64-w64-mingw32/include/c++/v1/type_traits:1811:38: error: implicit instantiation of undefined template 'std::hash'
: public integral_constant<bool, __is_empty(_Tp)> {};
^
/home/martin/clang-nightly/x86_64-w64-mingw32/include/c++/v1/unordered_map:453:18: note: in instantiation of template class 'std::is_empty<std::hash>' requested here
bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value>
^
/home/martin/clang-nightly/x86_64-w64-mingw32/include/c++/v1/unordered_map:936:13: note: in instantiation of default argument for '__unordered_map_hasher<MyEnum, std::__hash_value_type<MyEnum, int>, std::hash, std::equal_to>' required here
typedef __unordered_map_hasher<key_type, __value_type, hasher, key_equal> __hasher;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libcxx-unordered-map.cpp:3:33: note: in instantiation of template class 'std::unordered_map<MyEnum, int>' requested here
std::unordered_map<MyEnum, int> myMap;
^
/home/martin/clang-nightly/x86_64-w64-mingw32/include/c++/v1/__memory/shared_ptr.h:1688:50: note: template is declared here
template struct _LIBCPP_TEMPLATE_VIS hash;
^
1 error generated.

This causes build errors when building libaom since https://aomedia-review.googlesource.com/c/aom/+/136604.

@mstorsjo
Copy link
Member Author

mstorsjo commented May 7, 2021

assigned to @ldionne

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@Quuxplusone
Copy link
Contributor

This is simply because libc++'s std::hash<Enum> (the resolution of LWG2148, implemented in commit 5155a56) is enabled only in C++14-and-later, whereas libstdc++ and MSVC both DR it back to C++11.

It seems like the right fix here is to change our > 11 to >= 11, reenable a test or two, and ship it.

@ldionne
Copy link
Member

ldionne commented Feb 15, 2022

We normally DR LWG issue resolutions, so I think this is fine to do. @Quuxplusone do you want to put up a patch?

@Quuxplusone Quuxplusone assigned Quuxplusone and unassigned ldionne Feb 15, 2022
@Quuxplusone
Copy link
Contributor

This is now https://reviews.llvm.org/D119891

@Quuxplusone Quuxplusone added the confirmed Verified by a second party label Feb 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla confirmed Verified by a second party libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

3 participants