From: Jonas Toth Date: Mon, 3 Dec 2018 19:41:04 +0000 (+0000) Subject: [clang-tidy] Fix unordered_map failure with specializing std::hash<> and remove previ... X-Git-Tag: llvmorg-8.0.0-rc1~3028 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3f51ee19aec83bfd9de7289c0d5c9f7929abd2da;p=platform%2Fupstream%2Fllvm.git [clang-tidy] Fix unordered_map failure with specializing std::hash<> and remove previous wrong attempt at doing so llvm-svn: 348172 --- diff --git a/clang-tools-extra/clang-tidy/abseil/DurationComparisonCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationComparisonCheck.cpp index 15d0344..d5eb81b 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationComparisonCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/DurationComparisonCheck.cpp @@ -47,8 +47,7 @@ static llvm::Optional getScaleForInverse(llvm::StringRef Name) { static const std::pair & getInverseForScale(DurationScale Scale) { static const std::unordered_map, - std::hash> + std::pair> InverseMap( {{DurationScale::Hours, std::make_pair("::absl::ToDoubleHours", "::absl::ToInt64Hours")}, diff --git a/clang-tools-extra/clang-tidy/abseil/DurationRewriter.h b/clang-tools-extra/clang-tidy/abseil/DurationRewriter.h index f5d2e0d..aac241f 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationRewriter.h +++ b/clang-tools-extra/clang-tidy/abseil/DurationRewriter.h @@ -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::type; + using result_type = std::hash::result_type; + + result_type operator()(const argument_type &arg) const { + std::hash hasher; + return hasher(static_cast(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);