[clang-tools-extra] r348172 - [clang-tidy] Fix unordered_map failure with specializing std::hash<> and remove previous wrong attempt at doing so

Jonas Toth via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 3 11:41:04 PST 2018


Author: jonastoth
Date: Mon Dec  3 11:41:04 2018
New Revision: 348172

URL: http://llvm.org/viewvc/llvm-project?rev=348172&view=rev
Log:
[clang-tidy] Fix unordered_map failure with specializing std::hash<> and remove previous wrong attempt at doing so

Modified:
    clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp
    clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.h

Modified: clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp?rev=348172&r1=348171&r2=348172&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp Mon Dec  3 11:41:04 2018
@@ -47,8 +47,7 @@ static llvm::Optional<DurationScale> get
 static const std::pair<llvm::StringRef, llvm::StringRef> &
 getInverseForScale(DurationScale Scale) {
   static const std::unordered_map<DurationScale,
-                                  std::pair<llvm::StringRef, llvm::StringRef>,
-                                  std::hash<std::int8>>
+                                  std::pair<llvm::StringRef, llvm::StringRef>>
       InverseMap(
           {{DurationScale::Hours,
             std::make_pair("::absl::ToDoubleHours", "::absl::ToInt64Hours")},

Modified: clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.h?rev=348172&r1=348171&r2=348172&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.h (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.h Mon Dec  3 11:41:04 2018
@@ -27,7 +27,26 @@ enum class DurationScale : std::int8_t {
   Microseconds,
   Nanoseconds,
 };
+} // namespace abseil
+} // namespace tidy
+} // namespace clang
 
+namespace std {
+template <> struct hash<::clang::tidy::abseil::DurationScale> {
+  using argument_type = ::clang::tidy::abseil::DurationScale;
+  using underlying_type = std::underlying_type<argument_type>::type;
+  using result_type = std::hash<underlying_type>::result_type;
+
+  result_type operator()(const argument_type &arg) const {
+    std::hash<underlying_type> hasher;
+    return hasher(static_cast<underlying_type>(arg));
+  }
+};
+} // namespace std
+
+namespace clang {
+namespace tidy {
+namespace abseil {
 /// Given a `Scale`, return the appropriate factory function call for
 /// constructing a `Duration` for that scale.
 llvm::StringRef getFactoryForScale(DurationScale Scale);




More information about the cfe-commits mailing list