Browse Source

Added include fixits for C warnings beginning with: implicitly declaring library function

pipelines/235045657
eidheim 5 years ago
parent
commit
85b19da51b
  1. 53
      src/source_clang.cpp

53
src/source_clang.cpp

@ -390,12 +390,13 @@ void Source::ClangViewParse::update_diagnostics() {
diagnostic.fix_its.emplace_back(clangmm::Diagnostic::FixIt{"#include <" + *cpp_header + ">\n", file_path.string(), get_new_include_offsets()});
}
};
if(diagnostic.fix_its.empty() && diagnostic.severity >= clangmm::Diagnostic::Severity::Error) {
if(diagnostic.fix_its.empty() && diagnostic.severity >= clangmm::Diagnostic::Severity::Warning) {
for(size_t c = 0; c < clang_tokens->size(); c++) {
auto &token = (*clang_tokens)[c];
auto &token_offsets = clang_tokens_offsets[c];
if(static_cast<unsigned int>(line) == token_offsets.first.line - 1 && static_cast<unsigned int>(index) >= token_offsets.first.index - 1 && static_cast<unsigned int>(index) <= token_offsets.second.index - 1) {
if(starts_with(diagnostic.spelling, "implicit instantiation of undefined template")) {
if(diagnostic.severity >= clangmm::Diagnostic::Severity::Error &&
starts_with(diagnostic.spelling, "implicit instantiation of undefined template")) {
size_t start = 44 + 2;
if(start < diagnostic.spelling.size()) {
auto end = diagnostic.spelling.find('<', start);
@ -417,30 +418,34 @@ void Source::ClangViewParse::update_diagnostics() {
}
}
}
if(is_token_char(*start) && token.get_kind() == clangmm::Token::Kind::Identifier &&
(starts_with(diagnostic.spelling, "unknown type name") ||
starts_with(diagnostic.spelling, "no type named") ||
starts_with(diagnostic.spelling, "no member named") ||
starts_with(diagnostic.spelling, "no template named") ||
starts_with(diagnostic.spelling, "use of undeclared identifier") ||
starts_with(diagnostic.spelling, "implicit instantiation of undefined template") ||
starts_with(diagnostic.spelling, "no viable constructor or deduction guide for deduction of template arguments of"))) {
auto token_string = get_token(start);
bool has_std = false;
if(is_cpp) {
if(token_string == "std" && c + 2 < clang_tokens->size() && (*clang_tokens)[c + 2].get_kind() == clangmm::Token::Kind::Identifier) {
token_string = (*clang_tokens)[c + 2].get_spelling();
has_std = true;
if(is_token_char(*start) && token.get_kind() == clangmm::Token::Kind::Identifier) {
if(diagnostic.severity >= clangmm::Diagnostic::Severity::Error &&
(starts_with(diagnostic.spelling, "unknown type name") ||
starts_with(diagnostic.spelling, "no type named") ||
starts_with(diagnostic.spelling, "no member named") ||
starts_with(diagnostic.spelling, "no template named") ||
starts_with(diagnostic.spelling, "use of undeclared identifier") ||
starts_with(diagnostic.spelling, "implicit instantiation of undefined template") ||
starts_with(diagnostic.spelling, "no viable constructor or deduction guide for deduction of template arguments of"))) {
auto token_string = get_token(start);
bool has_std = false;
if(is_cpp) {
if(token_string == "std" && c + 2 < clang_tokens->size() && (*clang_tokens)[c + 2].get_kind() == clangmm::Token::Kind::Identifier) {
token_string = (*clang_tokens)[c + 2].get_spelling();
has_std = true;
}
else if(c >= 2 &&
(*clang_tokens)[c - 1].get_kind() == clangmm::Token::Punctuation &&
(*clang_tokens)[c - 2].get_kind() == clangmm::Token::Identifier &&
(*clang_tokens)[c - 1].get_spelling() == "::" &&
(*clang_tokens)[c - 2].get_spelling() == "std")
has_std = true;
}
else if(c >= 2 &&
(*clang_tokens)[c - 1].get_kind() == clangmm::Token::Punctuation &&
(*clang_tokens)[c - 2].get_kind() == clangmm::Token::Identifier &&
(*clang_tokens)[c - 1].get_spelling() == "::" &&
(*clang_tokens)[c - 2].get_spelling() == "std")
has_std = true;
add_include_fixit(has_std, is_cpp && has_using_namespace_std(c), token_string);
}
add_include_fixit(has_std, is_cpp && has_using_namespace_std(c), token_string);
else if(diagnostic.severity >= clangmm::Diagnostic::Severity::Warning && is_c &&
starts_with(diagnostic.spelling, "implicitly declaring library function"))
add_include_fixit(false, false, get_token(start));
}
break;
}

Loading…
Cancel
Save