Applied clang-tidy nullptr access warnings

This commit is contained in:
Bartek Kryza
2022-12-23 21:26:15 +01:00
parent aecbbd704b
commit f07dc35e06
6 changed files with 164 additions and 147 deletions

View File

@@ -171,7 +171,7 @@ std::string to_string(const clang::Expr *expr)
clang::LangOptions lang_options;
std::string result;
llvm::raw_string_ostream ostream(result);
expr->printPretty(ostream, NULL, clang::PrintingPolicy(lang_options));
expr->printPretty(ostream, nullptr, clang::PrintingPolicy(lang_options));
return result;
}
@@ -181,7 +181,7 @@ std::string to_string(const clang::Stmt *stmt)
clang::LangOptions lang_options;
std::string result;
llvm::raw_string_ostream ostream(result);
stmt->printPretty(ostream, NULL, clang::PrintingPolicy(lang_options));
stmt->printPretty(ostream, nullptr, clang::PrintingPolicy(lang_options));
return result;
}
@@ -284,15 +284,15 @@ template <> id_t to_id(const std::filesystem::path &file)
template <> id_t to_id(const clang::TemplateArgument &template_argument)
{
if (template_argument.getKind() == clang::TemplateArgument::Type) {
if (template_argument.getAsType()->getAs<clang::EnumType>() != nullptr)
return to_id(*template_argument.getAsType()
->getAs<clang::EnumType>()
->getAsTagDecl());
if (template_argument.getAsType()->getAs<clang::RecordType>() !=
nullptr)
return to_id(*template_argument.getAsType()
->getAs<clang::RecordType>()
->getAsRecordDecl());
if (const auto *enum_type =
template_argument.getAsType()->getAs<clang::EnumType>();
enum_type != nullptr)
return to_id(*enum_type->getAsTagDecl());
if (const auto *record_type =
template_argument.getAsType()->getAs<clang::RecordType>();
record_type != nullptr)
return to_id(*record_type->getAsRecordDecl());
}
throw std::runtime_error("Cannot generate id for template argument");

View File

@@ -71,7 +71,7 @@ public:
bool should_include(relationship_t r) const;
bool should_include(access_t s) const;
virtual bool has_element(const diagram_element::id_t /*id*/) const
virtual bool has_element(const diagram_element::id_t /*id*/) const
{
return false;
}

View File

@@ -160,6 +160,9 @@ void clang_visitor::visit_param_command(
std::string description;
if (command == nullptr)
return;
const auto name = command->getParamNameAsWritten().str();
for (const auto *it = command->child_begin(); it != command->child_end();
@@ -192,6 +195,9 @@ void clang_visitor::visit_tparam_command(
std::string description;
if (command == nullptr)
return;
const auto name = command->getParamNameAsWritten().str();
for (const auto *it = command->child_begin(); it != command->child_end();
@@ -220,12 +226,16 @@ void clang_visitor::visit_paragraph(
using clang::comments::Comment;
using clang::comments::TextComment;
if (paragraph == nullptr)
return;
for (const auto *text_it = paragraph->child_begin();
text_it != paragraph->child_end(); ++text_it) {
if ((*text_it)->getCommentKind() == Comment::TextCommentKind) {
if ((*text_it)->getCommentKind() == Comment::TextCommentKind &&
clang::dyn_cast<TextComment>(*text_it) != nullptr) {
// Merge paragraph lines into a single string
text += clang::dyn_cast<TextComment>((*text_it))->getText();
text += clang::dyn_cast<TextComment>(*text_it)->getText();
text += "\n";
}
}