Fix clang-tidy warning after upgrading to clang-tidy-15

This commit is contained in:
Bartek Kryza
2023-03-02 00:33:28 +01:00
parent 884e021b9a
commit 464d80eca3
25 changed files with 114 additions and 78 deletions

View File

@@ -184,7 +184,7 @@ std::string to_string(const clang::RecordType &type,
std::string to_string(const clang::Expr *expr)
{
clang::LangOptions lang_options;
const clang::LangOptions lang_options;
std::string result;
llvm::raw_string_ostream ostream(result);
expr->printPretty(ostream, nullptr, clang::PrintingPolicy(lang_options));
@@ -194,7 +194,7 @@ std::string to_string(const clang::Expr *expr)
std::string to_string(const clang::Stmt *stmt)
{
clang::LangOptions lang_options;
const clang::LangOptions lang_options;
std::string result;
llvm::raw_string_ostream ostream(result);
stmt->printPretty(ostream, nullptr, clang::PrintingPolicy(lang_options));
@@ -254,7 +254,7 @@ std::string get_source_text_raw(
std::string get_source_text(
clang::SourceRange range, const clang::SourceManager &sm)
{
clang::LangOptions lo;
const clang::LangOptions lo;
auto start_loc = sm.getSpellingLoc(range.getBegin());
auto last_token_loc = sm.getSpellingLoc(range.getEnd());
@@ -386,8 +386,7 @@ std::vector<common::model::template_parameter> parse_unexposed_template_params(
nested_params_str, ns_resolve, depth + 1);
if (nested_params.empty())
nested_params.emplace_back(
template_parameter{nested_params_str});
nested_params.emplace_back(nested_params_str);
it = bracket_match_end - 1;
}

View File

@@ -27,7 +27,6 @@ template <typename T> class nested_element_stack {
public:
nested_element_stack(bool is_flat)
: is_flat_{is_flat}
, current_level_{0}
{
current_level_groups_.push_back({});
}
@@ -66,7 +65,7 @@ public:
private:
bool is_flat_;
uint32_t current_level_;
uint32_t current_level_{0};
std::vector<std::map<std::string, std::vector<T *>>> current_level_groups_;
};

View File

@@ -212,8 +212,9 @@ inja::json generator<C, D>::element_context(const E &e) const
ctx["element"]["source"]["line"] = e.line();
}
if (e.comment().has_value()) {
ctx["element"]["comment"] = e.comment().value();
const auto maybe_comment = e.comment();
if (maybe_comment) {
ctx["element"]["comment"] = maybe_comment.value();
}
return ctx;

View File

@@ -492,12 +492,12 @@ void diagram_filter::init_filters(const config::diagram &c)
std::vector<std::string> dependencies;
for (auto &&path : c.include().dependants) {
std::filesystem::path dep_path{path};
const std::filesystem::path dep_path{path};
dependants.emplace_back(dep_path.lexically_normal().string());
}
for (auto &&path : c.include().dependencies) {
std::filesystem::path dep_path{path};
const std::filesystem::path dep_path{path};
dependencies.emplace_back(dep_path.lexically_normal().string());
}

View File

@@ -45,8 +45,8 @@ inja::json element::context() const
ctx["alias"] = alias();
ctx["full_name"] = full_name(false);
ctx["namespace"] = get_namespace().to_string();
if (comment().has_value()) {
ctx["comment"] = comment().value();
if (const auto maybe_comment = comment(); maybe_comment.has_value()) {
ctx["comment"] = maybe_comment.value();
}
return ctx;

View File

@@ -45,7 +45,10 @@ public:
std::copy(begin, end, std::back_inserter(path_));
}
path(const path &right) { path_ = right.path_; }
path(const path &right)
: path_{right.path_}
{
}
path &operator=(const path &right) = default;

View File

@@ -148,18 +148,21 @@ std::string template_parameter::to_string(
res += namespace_{type()}.relative_to(using_namespace).to_string();
}
if (concept_constraint()) {
const auto &maybe_concept_constraint = concept_constraint();
if (maybe_concept_constraint) {
if (!relative)
res += namespace_{concept_constraint().value()}.to_string();
res += namespace_{maybe_concept_constraint.value()}.to_string();
else
res += namespace_{concept_constraint().value()}
res += namespace_{maybe_concept_constraint.value()}
.relative_to(using_namespace)
.to_string();
}
if (!name().empty()) {
if (!type().empty() || concept_constraint())
if (!type().empty() || maybe_concept_constraint)
res += " ";
if (!relative)
res += namespace_{name()}.to_string();
else
@@ -169,6 +172,7 @@ std::string template_parameter::to_string(
// Render nested template params
if (!template_params_.empty()) {
std::vector<std::string> params;
params.reserve(template_params_.size());
for (const auto &template_param : template_params_) {
params.push_back(
template_param.to_string(using_namespace, relative));
@@ -197,8 +201,9 @@ bool template_parameter::find_nested_relationships(
// If this type argument should be included in the relationship
// just add it and skip recursion (e.g. this is a user defined type)
if (should_include(name())) {
if (id()) {
nested_relationships.emplace_back(id().value(), hint);
const auto maybe_id = id();
if (maybe_id) {
nested_relationships.emplace_back(maybe_id.value(), hint);
added_aggregation_relationship =
(hint == common::model::relationship_t::kAggregation);
}
@@ -207,11 +212,10 @@ bool template_parameter::find_nested_relationships(
// interested what is stored inside it
else {
for (const auto &template_argument : template_params()) {
if (should_include(template_argument.name()) &&
template_argument.id()) {
const auto maybe_id = template_argument.id();
if (should_include(template_argument.name()) && maybe_id) {
nested_relationships.emplace_back(
template_argument.id().value(), hint);
nested_relationships.emplace_back(maybe_id.value(), hint);
added_aggregation_relationship =
(hint == common::model::relationship_t::kAggregation);

View File

@@ -27,7 +27,6 @@ std::ostream &template_trait::render_template_params(std::ostream &ostr,
if (!templates_.empty()) {
std::vector<std::string> tnames;
std::vector<std::string> tnames_simplified;
std::transform(templates_.cbegin(), templates_.cend(),
std::back_inserter(tnames),

View File

@@ -33,23 +33,38 @@ public:
optional_ref() = default;
optional_ref(T *value) { value_ = value; }
optional_ref(T *value)
: value_{value}
{
}
optional_ref(const T *value) { value_ = value; }
optional_ref(const T *value)
: value_{value}
{
}
optional_ref(T &value) { value_ = &value; }
optional_ref(T &value)
: value_{&value}
{
}
optional_ref(const T &value) { value_ = &value; }
optional_ref(const T &value)
: value_{&value}
{
}
optional_ref(optional_ref &right) { value_ = right.get(); }
optional_ref(optional_ref &right)
: value_{right.get()}
{
}
template <typename V,
typename = std::enable_if<
std::is_base_of_v<optional_type, typename V::optional_type> ||
std::is_same_v<optional_type, typename V::optional_type>>>
optional_ref(const V &t)
: value_{t.get()}
{
value_ = t.get();
}
template <typename V,
@@ -57,16 +72,16 @@ public:
std::is_base_of_v<optional_type, typename V::optional_type> ||
std::is_same_v<optional_type, typename V::optional_type>>>
optional_ref(V &&t)
: value_{t.get()}
{
value_ = t.get();
t.reset();
}
template <typename V,
typename = std::enable_if<std::is_base_of_v<optional_type, V>>>
optional_ref(const std::reference_wrapper<V> &t)
: value_{&t.get()}
{
value_ = &t.get();
}
optional_ref &operator=(const optional_ref &right)

View File

@@ -53,6 +53,8 @@ public:
explicit translation_unit_visitor(
clang::SourceManager &sm, const clanguml::config::diagram &config);
virtual ~translation_unit_visitor() = default;
/**
* @brief Get clang::SourceManager
* @return Reference to @link clang::SourceManager used by this translation