[clang-tidy] Fix unordered_map failure with specializing std::hash<> and remove previ...
authorJonas Toth <jonas.toth@gmail.com>
Mon, 3 Dec 2018 19:41:04 +0000 (19:41 +0000)
committerJonas Toth <jonas.toth@gmail.com>
Mon, 3 Dec 2018 19:41:04 +0000 (19:41 +0000)
llvm-svn: 348172

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

index 15d0344..d5eb81b 100644 (file)
@@ -47,8 +47,7 @@ static llvm::Optional<DurationScale> getScaleForInverse(llvm::StringRef Name) {
 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")},
index f5d2e0d..aac241f 100644 (file)
@@ -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);