From aaa5008ec618c8962553f768a3cb90e55312e568 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 11 Nov 2018 01:10:15 -0800 Subject: [PATCH] Fix some MSVC 2017 errors Thanks to Dso Tsin! --- src/position.cc | 7 ++----- src/position.hh | 8 +++----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/position.cc b/src/position.cc index fc0458f8..23a97b75 100644 --- a/src/position.cc +++ b/src/position.cc @@ -5,6 +5,7 @@ #include "serializer.hh" +#include #include #include #include @@ -45,14 +46,10 @@ Range Range::FromString(const std::string &encoded) { bool Range::Contains(int line, int column) const { if (line > INT16_MAX) return false; - Pos p{int16_t(line), int16_t(std::min(column, INT16_MAX))}; + Pos p{(int16_t)line, (int16_t)std::min(column, INT16_MAX)}; return !(p < start) && p < end; } -Range Range::RemovePrefix(Pos position) const { - return {std::min(std::max(position, start), end), end}; -} - std::string Range::ToString() { char buf[99]; snprintf(buf, sizeof buf, "%d:%d-%d:%d", start.line + 1, start.column + 1, diff --git a/src/position.hh b/src/position.hh index b3f06142..f92d24b7 100644 --- a/src/position.hh +++ b/src/position.hh @@ -40,7 +40,6 @@ struct Range { bool Valid() const { return start.Valid(); } bool Contains(int line, int column) const; - Range RemovePrefix(Pos position) const; std::string ToString(); @@ -64,12 +63,11 @@ void Reflect(Writer &visitor, Range &value); namespace std { template <> struct hash { std::size_t operator()(ccls::Range x) const { - union U { - ccls::Range range = {}; + union { + ccls::Range range; uint64_t u64; - } u; + } u{x}; static_assert(sizeof(ccls::Range) == 8); - u.range = x; return hash()(u.u64); } };