diff --git a/src/class_diagram/visitor/translation_unit_visitor.cc b/src/class_diagram/visitor/translation_unit_visitor.cc index 6b05d751..221fd7d8 100644 --- a/src/class_diagram/visitor/translation_unit_visitor.cc +++ b/src/class_diagram/visitor/translation_unit_visitor.cc @@ -1795,6 +1795,10 @@ void translation_unit_visitor::process_field( relationship_hint = relationship_t::kAssociation; field_type = field_type.getNonReferenceType(); } + else if (field_type->isArrayType()) { + relationship_hint = relationship_t::kAggregation; + field_type = field_type->getAsArrayTypeUnsafe()->getElementType(); + } else if (field_type->isRValueReferenceType()) { field_type = field_type.getNonReferenceType(); } diff --git a/src/common/clang_utils.cc b/src/common/clang_utils.cc index 38881b9e..c928a158 100644 --- a/src/common/clang_utils.cc +++ b/src/common/clang_utils.cc @@ -116,6 +116,12 @@ std::string get_tag_name(const clang::TagDecl &declaration) std::string to_string(const clang::QualType &type, const clang::ASTContext &ctx, bool try_canonical) { + if (type->isArrayType()) { + return fmt::format("{}[]", + to_string(type->getAsArrayTypeUnsafe()->getElementType(), ctx, + try_canonical)); + } + clang::PrintingPolicy print_policy(ctx.getLangOpts()); print_policy.SuppressScope = 0; print_policy.PrintCanonicalTypes = 0; @@ -150,8 +156,8 @@ std::string to_string(const clang::QualType &type, const clang::ASTContext &ctx, result = "(anonymous)"; else if (util::contains(result, "unnamed struct") || util::contains(result, "unnamed union")) { - auto declarationTag = type->getAsTagDecl(); - if (declarationTag == NULL) { + const auto *declarationTag = type->getAsTagDecl(); + if (declarationTag == nullptr) { result = "(unnamed undeclared)"; } else { diff --git a/tests/t00037/t00037.cc b/tests/t00037/t00037.cc index 55b46f36..e9d73f9b 100644 --- a/tests/t00037/t00037.cc +++ b/tests/t00037/t00037.cc @@ -1,6 +1,8 @@ namespace clanguml { namespace t00037 { +constexpr auto LENGTH{10ULL}; + class ST { public: struct { @@ -10,6 +12,11 @@ public: double z; } dimensions; + struct { + int len; + int flags; + } __attribute__((packed)) bars[LENGTH]; + private: struct { double c{1.0}; diff --git a/tests/t00037/test_case.h b/tests/t00037/test_case.h index 662bccbc..2c18a940 100644 --- a/tests/t00037/test_case.h +++ b/tests/t00037/test_case.h @@ -30,9 +30,11 @@ TEST_CASE("t00037") REQUIRE(IsClass(src, "A")); REQUIRE(IsClass(src, "ST::(units)")); REQUIRE(IsClass(src, "ST::(dimensions)")); + REQUIRE(IsClass(src, "ST::(bars)")); REQUIRE( IsAggregation(src, "ST", "ST::(dimensions)", "dimensions")); REQUIRE(IsAggregation(src, "ST", "ST::(units)", "units")); + REQUIRE(IsAggregation(src, "ST", "ST::(bars)", "bars")); }); } \ No newline at end of file