Skip to content

Commit

Permalink
Fix missing std::tr1::hash on GCC 4.1 (#2907)
Browse files Browse the repository at this point in the history
Rather than crashing on use (doh!) better to just declare this platform
is missing a proper hash_map/hash_set implementation and use
the std::map/std::set emulation.

Fixes regression introduced by #1913
  • Loading branch information
matthauck authored and xfxyjwf committed Jul 10, 2017
1 parent 126082c commit 9ab7c73
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/google/protobuf/stubs/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

#define GOOGLE_PROTOBUF_HAVE_HASH_MAP 1
#define GOOGLE_PROTOBUF_HAVE_HASH_SET 1
#define GOOGLE_PROTOBUF_HAVE_64BIT_HASH 1

// Use C++11 unordered_{map|set} if available.
#if ((_LIBCPP_STD_VER >= 11) || \
Expand Down Expand Up @@ -93,8 +92,11 @@
# define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set
# endif

// GCC <= 4.1 does not define std::tr1::hash for `long long int` or `long long unsigned int`
# if __GNUC__ == 4 && __GNUC__MINOR__ <= 1
# undef GOOGLE_PROTOBUF_HAVE_64BIT_HASH
# define GOOGLE_PROTOBUF_MISSING_HASH
# include <map>
# include <set>
# endif

// Version checks for MSC.
Expand Down

1 comment on commit 9ab7c73

@liujisi
Copy link
Contributor

@liujisi liujisi commented on 9ab7c73 Aug 30, 2017

Choose a reason for hiding this comment

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

Hey Matt, do you mind test if you can use other macros like __GLIBCXX__ instead of GCC versions? Clang seems to be defining __GNUC__ without defining __GNUC__MINOR__ but it typically depend on a newer version of standard library which supports 64 bit integer hash (e.g. 20150123). Maybe worth tracking the version in which hash was added in libstdc++?

Please sign in to comment.