Skip to content

Commit 6a488bf

Browse files
committed
Fix some clang-tidy warnings
Incorporated some fixes by Daniel Chabrowski (#467)
1 parent d61bf57 commit 6a488bf

18 files changed

+54
-51
lines changed

src/clang_tu.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ std::string pathFromFileEntry(const FileEntry &file) {
3636

3737
static Pos decomposed2LineAndCol(const SourceManager &sm,
3838
std::pair<FileID, unsigned> i) {
39-
int l = sm.getLineNumber(i.first, i.second) - 1,
40-
c = sm.getColumnNumber(i.first, i.second) - 1;
39+
int l = (int)sm.getLineNumber(i.first, i.second) - 1,
40+
c = (int)sm.getColumnNumber(i.first, i.second) - 1;
4141
bool invalid = false;
4242
StringRef buf = sm.getBufferData(i.first, &invalid);
4343
if (!invalid) {
@@ -114,7 +114,6 @@ const char *clangBuiltinTypeName(int kind) {
114114
case BuiltinType::Bool:
115115
return "bool";
116116
case BuiltinType::Char_S:
117-
return "char";
118117
case BuiltinType::Char_U:
119118
return "char";
120119
case BuiltinType::SChar:

src/fuzzy_match.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ FuzzyMatcher::FuzzyMatcher(std::string_view pattern, int sensitivity) {
101101
for (size_t i = 0; i < pattern.size(); i++)
102102
if (pattern[i] != ' ') {
103103
pat += pattern[i];
104-
low_pat[n] = ::tolower(pattern[i]);
104+
low_pat[n] = (char)::tolower(pattern[i]);
105105
pat_role[n] = pat_role[i];
106106
n++;
107107
}
@@ -115,7 +115,7 @@ int FuzzyMatcher::match(std::string_view text, bool strict) {
115115
return kMinScore + 1;
116116
this->text = text;
117117
for (int i = 0; i < n; i++)
118-
low_text[i] = ::tolower(text[i]);
118+
low_text[i] = (char)::tolower(text[i]);
119119
calculateRoles(text, text_role, &text_set);
120120
if (strict && n && !!pat_role[0] != !!text_role[0])
121121
return kMinScore;

src/indexer.cc

+2-4
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,7 @@ class IndexDataConsumer : public index::IndexDataConsumer {
461461
}
462462
while (ret.size() && isspace(ret.back()))
463463
ret.pop_back();
464-
if (StringRef(ret).endswith("*/"))
465-
ret.resize(ret.size() - 2);
466-
else if (StringRef(ret).endswith("\n/"))
464+
if (StringRef(ret).endswith("*/") || StringRef(ret).endswith("\n/"))
467465
ret.resize(ret.size() - 2);
468466
while (ret.size() && isspace(ret.back()))
469467
ret.pop_back();
@@ -676,7 +674,7 @@ class IndexDataConsumer : public index::IndexDataConsumer {
676674
rd->isInvalidDecl() || !validateRecord(rd))
677675
offset = -1;
678676
for (FieldDecl *fd : rd->fields()) {
679-
int offset1 = offset < 0 ? -1 : offset + ctx->getFieldOffset(fd);
677+
int offset1 = offset < 0 ? -1 : int(offset + ctx->getFieldOffset(fd));
680678
if (fd->getIdentifier())
681679
type.def.vars.emplace_back(getUsr(fd), offset1);
682680
else if (const auto *rt1 = fd->getType()->getAs<RecordType>()) {

src/lsp.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void reflect(JsonWriter &visitor, RequestId &value) {
4545
visitor.null_();
4646
break;
4747
case RequestId::kInt:
48-
visitor.int_(atoll(value.value.c_str()));
48+
visitor.int64(atoll(value.value.c_str()));
4949
break;
5050
case RequestId::kString:
5151
visitor.string(value.value.c_str(), value.value.size());
@@ -63,7 +63,7 @@ void DocumentUri::setPath(const std::string &path) {
6363
// file:///c%3A/Users/jacob/Desktop/superindex/indexer/full_tests
6464
raw_uri = path;
6565

66-
size_t index = raw_uri.find(":");
66+
size_t index = raw_uri.find(':');
6767
if (index == 1) { // widows drive letters must always be 1 char
6868
raw_uri.replace(raw_uri.begin() + index, raw_uri.begin() + index + 1,
6969
"%3A");

src/message_handler.cc

+2-4
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,8 @@ void ReplyOnce::replyLocationLink(std::vector<LocationLink> &result) {
121121
if (g_config->client.linkSupport) {
122122
(*this)(result);
123123
} else {
124-
std::vector<Location> result1;
125-
for (auto &loc : result)
126-
result1.emplace_back(std::move(loc));
127-
(*this)(result1);
124+
(*this)(std::vector<Location>(std::make_move_iterator(result.begin()),
125+
std::make_move_iterator(result.end())));
128126
}
129127
}
130128

src/message_handler.hh

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ struct WorkingFile;
3232
struct WorkingFiles;
3333

3434
namespace pipeline {
35-
void reply(RequestId id, const std::function<void(JsonWriter &)> &fn);
36-
void replyError(RequestId id, const std::function<void(JsonWriter &)> &fn);
35+
void reply(const RequestId &id, const std::function<void(JsonWriter &)> &fn);
36+
void replyError(const RequestId &id,
37+
const std::function<void(JsonWriter &)> &fn);
3738
} // namespace pipeline
3839

3940
struct CodeActionParam {

src/messages/initialize.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ void do_initialize(MessageHandler *m, InitializeParam &param,
382382
// may take a long time. Indexer threads will emit status/progress
383383
// reports.
384384
if (g_config->index.threads == 0)
385-
g_config->index.threads = std::thread::hardware_concurrency();
385+
g_config->index.threads = (int)std::thread::hardware_concurrency();
386386

387387
LOG_S(INFO) << "start " << g_config->index.threads << " indexers";
388388
for (int i = 0; i < g_config->index.threads; i++)

src/messages/textDocument_formatting.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ std::vector<TextEdit> replacementsToEdits(std::string_view code,
4444
const tooling::Replacements &repls) {
4545
std::vector<TextEdit> ret;
4646
int i = 0, line = 0, col = 0;
47-
auto move = [&](int p) {
48-
for (; i < p; i++)
47+
auto move = [&](unsigned p) {
48+
for (; i < (int)p; i++)
4949
if (code[i] == '\n')
5050
line++, col = 0;
5151
else {

src/messages/workspace.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void MessageHandler::workspace_didChangeWorkspaceFolders(
101101
if (folder == real)
102102
real.clear();
103103
LOG_S(INFO) << "add workspace folder " << wf.name << ": "
104-
<< (real.empty() ? folder : folder + " -> " + real);
104+
<< (real.empty() ? folder : (folder + " -> ").append(real));
105105
workspaceFolders.emplace_back();
106106
auto it = workspaceFolders.end() - 1;
107107
for (; it != workspaceFolders.begin() && folder < it[-1].first; --it)

src/pipeline.cc

+12-10
Original file line numberDiff line numberDiff line change
@@ -616,13 +616,13 @@ void mainLoop() {
616616

617617
SemaManager manager(
618618
&project, &wfiles,
619-
[&](std::string path, std::vector<Diagnostic> diagnostics) {
619+
[](const std::string &path, std::vector<Diagnostic> diagnostics) {
620620
PublishDiagnosticParam params;
621621
params.uri = DocumentUri::fromPath(path);
622-
params.diagnostics = diagnostics;
622+
params.diagnostics = std::move(diagnostics);
623623
notify("textDocument/publishDiagnostics", params);
624624
},
625-
[](RequestId id) {
625+
[](const RequestId &id) {
626626
if (id.valid()) {
627627
ResponseError err;
628628
err.code = ErrorCode::InternalError;
@@ -717,8 +717,9 @@ void standalone(const std::string &root) {
717717
WorkingFiles wfiles;
718718
VFS vfs;
719719
SemaManager manager(
720-
nullptr, nullptr, [&](std::string, std::vector<Diagnostic>) {},
721-
[](RequestId id) {});
720+
nullptr, nullptr,
721+
[](const std::string &, const std::vector<Diagnostic> &) {},
722+
[](const RequestId &id) {});
722723
IncludeComplete complete(&project);
723724

724725
MessageHandler handler;
@@ -756,7 +757,7 @@ void standalone(const std::string &root) {
756757
void index(const std::string &path, const std::vector<const char *> &args,
757758
IndexMode mode, bool must_exist, RequestId id) {
758759
pending_index_requests++;
759-
index_request->pushBack({path, args, mode, must_exist, id},
760+
index_request->pushBack({path, args, mode, must_exist, std::move(id)},
760761
mode != IndexMode::Background);
761762
}
762763

@@ -800,7 +801,7 @@ void notifyOrRequest(const char *method, bool request,
800801
for_stdout->pushBack(output.GetString());
801802
}
802803

803-
static void reply(RequestId id, const char *key,
804+
static void reply(const RequestId &id, const char *key,
804805
const std::function<void(JsonWriter &)> &fn) {
805806
rapidjson::StringBuffer output;
806807
rapidjson::Writer<rapidjson::StringBuffer> w(output);
@@ -813,7 +814,7 @@ static void reply(RequestId id, const char *key,
813814
w.Null();
814815
break;
815816
case RequestId::kInt:
816-
w.Int(atoll(id.value.c_str()));
817+
w.Int64(atoll(id.value.c_str()));
817818
break;
818819
case RequestId::kString:
819820
w.String(id.value.c_str(), id.value.size());
@@ -828,11 +829,12 @@ static void reply(RequestId id, const char *key,
828829
for_stdout->pushBack(output.GetString());
829830
}
830831

831-
void reply(RequestId id, const std::function<void(JsonWriter &)> &fn) {
832+
void reply(const RequestId &id, const std::function<void(JsonWriter &)> &fn) {
832833
reply(id, "result", fn);
833834
}
834835

835-
void replyError(RequestId id, const std::function<void(JsonWriter &)> &fn) {
836+
void replyError(const RequestId &id,
837+
const std::function<void(JsonWriter &)> &fn) {
836838
reply(id, "error", fn);
837839
}
838840
} // namespace pipeline

src/pipeline.hh

+4-3
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ template <typename T> void request(const char *method, T &result) {
6565
notifyOrRequest(method, true, [&](JsonWriter &w) { reflect(w, result); });
6666
}
6767

68-
void reply(RequestId id, const std::function<void(JsonWriter &)> &fn);
68+
void reply(const RequestId &id, const std::function<void(JsonWriter &)> &fn);
6969

70-
void replyError(RequestId id, const std::function<void(JsonWriter &)> &fn);
71-
template <typename T> void replyError(RequestId id, T &result) {
70+
void replyError(const RequestId &id,
71+
const std::function<void(JsonWriter &)> &fn);
72+
template <typename T> void replyError(const RequestId &id, T &result) {
7273
replyError(id, [&](JsonWriter &w) { reflect(w, result); });
7374
}
7475
} // namespace pipeline

src/project.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ bool appendToCDB(const std::vector<const char *> &args) {
249249
return args.size() && StringRef("%compile_commands.json") == args[0];
250250
}
251251

252-
std::vector<const char *> getFallback(const std::string path) {
252+
std::vector<const char *> getFallback(const std::string &path) {
253253
std::vector<const char *> argv{"clang"};
254254
if (sys::path::extension(path) == ".h")
255255
argv.push_back("-xobjective-c++-header");
@@ -607,7 +607,7 @@ Project::Entry Project::findEntry(const std::string &path, bool can_redirect,
607607
return ret;
608608
}
609609

610-
void Project::index(WorkingFiles *wfiles, RequestId id) {
610+
void Project::index(WorkingFiles *wfiles, const RequestId &id) {
611611
auto &gi = g_config->index;
612612
GroupMatch match(gi.whitelist, gi.blacklist),
613613
match_i(gi.initialWhitelist, gi.initialBlacklist);

src/project.hh

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct Project {
7676
void setArgsForFile(const std::vector<const char *> &args,
7777
const std::string &path);
7878

79-
void index(WorkingFiles *wfiles, RequestId id);
79+
void index(WorkingFiles *wfiles, const RequestId &id);
8080
void indexRelated(const std::string &path);
8181
};
8282
} // namespace ccls

src/query.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ IndexUpdate IndexUpdate::createDelta(IndexFile *previous, IndexFile *current) {
135135
previous = &empty;
136136
r.lid2path = std::move(current->lid2path);
137137

138-
r.funcs_hint = current->usr2func.size() - previous->usr2func.size();
138+
r.funcs_hint = int(current->usr2func.size() - previous->usr2func.size());
139139
for (auto &it : previous->usr2func) {
140140
auto &func = it.second;
141141
if (func.def.detailed_name[0])
@@ -153,7 +153,7 @@ IndexUpdate IndexUpdate::createDelta(IndexFile *previous, IndexFile *current) {
153153
r.funcs_derived[func.usr].second = std::move(func.derived);
154154
}
155155

156-
r.types_hint = current->usr2type.size() - previous->usr2type.size();
156+
r.types_hint = int(current->usr2type.size() - previous->usr2type.size());
157157
for (auto &it : previous->usr2type) {
158158
auto &type = it.second;
159159
if (type.def.detailed_name[0])
@@ -173,7 +173,7 @@ IndexUpdate IndexUpdate::createDelta(IndexFile *previous, IndexFile *current) {
173173
r.types_instances[type.usr].second = std::move(type.instances);
174174
};
175175

176-
r.vars_hint = current->usr2var.size() - previous->usr2var.size();
176+
r.vars_hint = int(current->usr2var.size() - previous->usr2var.size());
177177
for (auto &it : previous->usr2var) {
178178
auto &var = it.second;
179179
if (var.def.detailed_name[0])

src/sema_manager.cc

+6-4
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ class StoreDiags : public DiagnosticConsumer {
231231
}
232232

233233
public:
234-
StoreDiags(std::string path) : path(path) {}
234+
StoreDiags(std::string path) : path(std::move(path)) {}
235235
std::vector<Diag> take() { return std::move(output); }
236236
bool isConcerned(const SourceManager &sm, SourceLocation l) {
237237
FileID fid = sm.getFileID(l);
@@ -615,7 +615,7 @@ void *diagnosticMain(void *manager_) {
615615
ret.severity = 1;
616616
break;
617617
}
618-
ret.code = d.category;
618+
ret.code = (int)d.category;
619619
return ret;
620620
};
621621

@@ -683,8 +683,10 @@ std::shared_ptr<PreambleData> Session::getPreamble() {
683683

684684
SemaManager::SemaManager(Project *project, WorkingFiles *wfiles,
685685
OnDiagnostic on_diagnostic, OnDropped on_dropped)
686-
: project_(project), wfiles(wfiles), on_diagnostic_(on_diagnostic),
687-
on_dropped_(on_dropped), pch(std::make_shared<PCHContainerOperations>()) {
686+
: project_(project), wfiles(wfiles),
687+
on_diagnostic_(std::move(on_diagnostic)),
688+
on_dropped_(std::move(on_dropped)),
689+
pch(std::make_shared<PCHContainerOperations>()) {
688690
spawnThread(ccls::preambleMain, this);
689691
spawnThread(ccls::completionMain, this);
690692
spawnThread(ccls::diagnosticMain, this);

src/serializer.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ limitations under the License.
2525

2626
#include <llvm/ADT/CachedHashString.h>
2727
#include <llvm/ADT/DenseSet.h>
28+
#include <llvm/ADT/STLExtras.h>
2829

2930
#include <mutex>
3031
#include <stdexcept>
@@ -35,7 +36,7 @@ bool gTestOutputMode = false;
3536

3637
namespace ccls {
3738

38-
void JsonReader::iterArray(std::function<void()> fn) {
39+
void JsonReader::iterArray(llvm::function_ref<void()> fn) {
3940
if (!m->IsArray())
4041
throw std::invalid_argument("array");
4142
// Use "0" to indicate any element for now.
@@ -48,7 +49,7 @@ void JsonReader::iterArray(std::function<void()> fn) {
4849
}
4950
path_.pop_back();
5051
}
51-
void JsonReader::member(const char *name, std::function<void()> fn) {
52+
void JsonReader::member(const char *name, llvm::function_ref<void()> fn) {
5253
path_.push_back(name);
5354
auto it = m->FindMember(name);
5455
if (it != m->MemberEnd()) {
@@ -81,7 +82,7 @@ void JsonWriter::startObject() { m->StartObject(); }
8182
void JsonWriter::endObject() { m->EndObject(); }
8283
void JsonWriter::key(const char *name) { m->Key(name); }
8384
void JsonWriter::null_() { m->Null(); }
84-
void JsonWriter::int_(int v) { m->Int(v); }
85+
void JsonWriter::int64(int64_t v) { m->Int64(v); }
8586
void JsonWriter::string(const char *s) { m->String(s); }
8687
void JsonWriter::string(const char *s, size_t len) { m->String(s, len); }
8788

src/serializer.hh

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ limitations under the License.
3434
namespace llvm {
3535
class CachedHashStringRef;
3636
class StringRef;
37+
template <typename Fn> class function_ref;
3738
} // namespace llvm
3839

3940
namespace ccls {
@@ -48,8 +49,8 @@ struct JsonReader {
4849
JsonReader(rapidjson::Value *m) : m(m) {}
4950
void startObject() {}
5051
void endObject() {}
51-
void iterArray(std::function<void()> fn);
52-
void member(const char *name, std::function<void()> fn);
52+
void iterArray(llvm::function_ref<void()> fn);
53+
void member(const char *name, llvm::function_ref<void()> fn);
5354
bool isNull();
5455
std::string getString();
5556
std::string getPath() const;
@@ -69,7 +70,7 @@ struct JsonWriter {
6970
void endObject();
7071
void key(const char *name);
7172
void null_();
72-
void int_(int v);
73+
void int64(int64_t v);
7374
void string(const char *s);
7475
void string(const char *s, size_t len);
7576
};

src/working_files.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ int alignColumn(const std::string &a, int column, std::string b, bool is_end) {
143143
if (column < head)
144144
return column;
145145
if ((int)a.size() - tail < column)
146-
return column + b.size() - a.size();
146+
return column + (int)b.size() - (int)a.size();
147147
if (std::max(a.size(), b.size()) - head - tail >= kMaxColumnAlignSize)
148148
return std::min(column, (int)b.size());
149149

0 commit comments

Comments
 (0)