From 3f45c05476e45773c4746e0cda41a242ceac507a Mon Sep 17 00:00:00 2001 From: Peter Goodman Date: Sat, 18 Nov 2017 14:13:48 -0500 Subject: [PATCH] This commit fixes severak compiler errors when trying to build cquery. I gave up after a bit and didn't fix them all though, there are a ton of signed to unsigned comparisons. --- src/clang_complete.cc | 4 ++-- src/indexer.h | 4 +++- src/language_server_api.cc | 4 ++-- src/lex_utils.cc | 2 +- src/platform.cc | 10 ++++++---- src/platform_linux.cc | 2 +- src/query.h | 2 +- src/serializer.h | 2 +- 8 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/clang_complete.cc b/src/clang_complete.cc index 3373b278..7afbf334 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -483,7 +483,7 @@ LruSessionCache::LruSessionCache(int max_entries) : max_entries_(max_entries) {} std::shared_ptr LruSessionCache::TryGetEntry( const std::string& filename) { - for (int i = 0; i < entries_.size(); ++i) { + for (size_t i = 0; i < entries_.size(); ++i) { if (entries_[i]->file.filename == filename) return entries_[i]; } @@ -492,7 +492,7 @@ std::shared_ptr LruSessionCache::TryGetEntry( std::shared_ptr LruSessionCache::TryTakeEntry( const std::string& filename) { - for (int i = 0; i < entries_.size(); ++i) { + for (size_t i = 0; i < entries_.size(); ++i) { if (entries_[i]->file.filename == filename) { std::shared_ptr result = entries_[i]; entries_.erase(entries_.begin() + i); diff --git a/src/indexer.h b/src/indexer.h index ed20c819..8d9fd5f7 100644 --- a/src/indexer.h +++ b/src/indexer.h @@ -132,7 +132,9 @@ inline void Reflect(Writer& visitor, IndexFuncRef& value) { if (value.is_implicit) s += "~"; - if (value.id.id == -1) { // id.id is unsigned, special case 0 value + + // id.id is unsigned, special case 0 value + if (static_cast(value.id.id) == -1) { s += "-1"; } else { s += std::to_string(value.id.id); diff --git a/src/language_server_api.cc b/src/language_server_api.cc index 71d5bc3c..abdf4d6d 100644 --- a/src/language_server_api.cc +++ b/src/language_server_api.cc @@ -240,12 +240,12 @@ std::string lsDocumentUri::GetPath() const { result = ReplaceAll(result, "%29", ")"); size_t index = result.find("%3A"); - if (index != -1) { + if (index != std::string::npos) { result.replace(result.begin() + index, result.begin() + index + 3, ":"); } index = result.find("file://"); - if (index != -1) { + if (index != std::string::npos) { // TODO: proper fix #if defined(_WIN32) result.replace(result.begin() + index, result.begin() + index + 8, ""); diff --git a/src/lex_utils.cc b/src/lex_utils.cc index 5a8dd401..8fcac602 100644 --- a/src/lex_utils.cc +++ b/src/lex_utils.cc @@ -11,7 +11,7 @@ int GetOffsetForPosition(lsPosition position, const std::string& content) { int offset = 0; int remaining_lines = position.line; - while (remaining_lines > 0 && offset < content.size()) { + while (remaining_lines > 0 && offset < static_cast(content.size())) { if (content[offset] == '\n') --remaining_lines; ++offset; diff --git a/src/platform.cc b/src/platform.cc index 5a90284c..b534f29b 100644 --- a/src/platform.cc +++ b/src/platform.cc @@ -28,10 +28,11 @@ std::vector Split(const std::string& s, char delim) { return elems; } -std::string Join(const std::vector& entries, char delim, int end) { +std::string Join(const std::vector& entries, char delim, + size_t end) { std::string result; bool first = true; - for (int i = 0; i < end; ++i) { + for (size_t i = 0; i < end; ++i) { if (!first) result += delim; first = false; @@ -62,7 +63,8 @@ void MakeDirectoryRecursive(std::string path) { // Find first parent directory which doesn't exist. int first_success = -1; - for (int i = (int)components.size(); i > 0; --i) { + for (size_t j = 0; j < components.size(); ++j) { + size_t i = components.size() - j; if (TryMakeDirectory(prefix + Join(components, '/', i))) { first_success = i; break; @@ -76,7 +78,7 @@ void MakeDirectoryRecursive(std::string path) { } // Make all child directories. - for (int i = first_success + 1; i <= components.size(); ++i) { + for (size_t i = first_success + 1; i <= components.size(); ++i) { if (TryMakeDirectory(prefix + Join(components, '/', i)) == false) { std::cerr << "Failed making directory for " << path << " even after creating parent directories" << std::endl; diff --git a/src/platform_linux.cc b/src/platform_linux.cc index af711698..3ef2fb24 100644 --- a/src/platform_linux.cc +++ b/src/platform_linux.cc @@ -157,7 +157,7 @@ std::string GetWorkingDirectory() { std::string NormalizePath(const std::string& path) { errno = 0; char name[PATH_MAX + 1]; - realpath(path.c_str(), name); + (void) realpath(path.c_str(), name); if (errno) return path; return name; diff --git a/src/query.h b/src/query.h index 53b6d4e2..9bc9db0b 100644 --- a/src/query.h +++ b/src/query.h @@ -110,7 +110,7 @@ struct QueryFuncRef { QueryLocation loc; bool is_implicit = false; - bool has_id() const { return id_.id != -1; } + bool has_id() const { return static_cast(id_.id) != -1; } QueryFuncRef() {} // Do not use, needed for reflect. QueryFuncRef(QueryFuncId id, QueryLocation loc, bool is_implicit) diff --git a/src/serializer.h b/src/serializer.h index 083a0d73..342e0bc1 100644 --- a/src/serializer.h +++ b/src/serializer.h @@ -180,7 +180,7 @@ template void Reflect(Reader& visitor, optional& value) { if (visitor.IsNull()) return; - T real_value; + T real_value{}; Reflect(visitor, real_value); value = real_value; }