From 20100d46d9447b864e6bf8b3d02a8d07aa1c0219 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 Dso Tsin! --- src/clang_tu.cc | 3 ++- src/lsp.cc | 1 + src/position.cc | 7 ++----- src/position.hh | 4 ++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/clang_tu.cc b/src/clang_tu.cc index 91fa2e38..5a87153a 100644 --- a/src/clang_tu.cc +++ b/src/clang_tu.cc @@ -45,7 +45,8 @@ static Pos Decomposed2LineAndCol(const SourceManager &SM, std::pair I) { int l = SM.getLineNumber(I.first, I.second) - 1, c = SM.getColumnNumber(I.first, I.second) - 1; - return {(int16_t)std::min(l, INT16_MAX), (int16_t)std::min(c, INT16_MAX)}; + return {(int16_t)std::min(l, INT16_MAX), + (int16_t)std::min(c, INT16_MAX)}; } Range FromCharSourceRange(const SourceManager &SM, const LangOptions &LangOpts, diff --git a/src/lsp.cc b/src/lsp.cc index 9adc2f42..3a95a9d8 100644 --- a/src/lsp.cc +++ b/src/lsp.cc @@ -18,6 +18,7 @@ limitations under the License. #include "log.hh" #include "serializers/json.hh" +#include #include namespace ccls { diff --git a/src/position.cc b/src/position.cc index 2a124c5b..b82d3097 100644 --- a/src/position.cc +++ b/src/position.cc @@ -17,6 +17,7 @@ limitations under the License. #include "serializer.hh" +#include #include #include #include @@ -57,14 +58,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 794c7af2..b06389f2 100644 --- a/src/position.hh +++ b/src/position.hh @@ -52,7 +52,6 @@ struct Range { bool Valid() const { return start.Valid(); } bool Contains(int line, int column) const; - Range RemovePrefix(Pos position) const; std::string ToString(); @@ -77,7 +76,8 @@ namespace std { template <> struct hash { std::size_t operator()(ccls::Range x) const { union U { - ccls::Range range = {}; + U() {} + ccls::Range range; uint64_t u64; } u; static_assert(sizeof(ccls::Range) == 8);