Skip to content

Modernize DpCatalog: in-class initializers and =default destructor#5068

Open
carlosvales wants to merge 2 commits intonasa:develfrom
carlosvales:fix/dpcatalog-modernize-init-s3230-s3490
Open

Modernize DpCatalog: in-class initializers and =default destructor#5068
carlosvales wants to merge 2 commits intonasa:develfrom
carlosvales:fix/dpcatalog-modernize-init-s3230-s3490

Conversation

@carlosvales
Copy link
Copy Markdown

Related Issue(s) #4521
Has Unit Tests (y/n) n
Documentation Included (y/n) n
Generative AI was used in this contribution (y/n) y

Change Description

Migrates the initialization of all scalar/pointer data members of Svc::DpCatalog from the constructor's member-initializer list to in-class default member initializers, and converts the empty destructor to = default.

The constructor body is now:

DpCatalog::DpCatalog(const char* const compName) : DpCatalogComponentBase(compName) {}

Object members (m_directories[], m_fileList[], m_stateFile, m_currXmitFileName) are unchanged because they are default-constructed and were not flagged.

Rationale

Resolves a cluster of SonarQube findings listed in #4521:

  • 22× cpp:S3230"Do not use the constructor's initializer list for data member ...; use the in-class initializer instead." (Medium)
  • cpp:S3490"Use =default instead of the default implementation of this special member function." (High)

The change is intentionally narrow and self-contained:

This pattern (in-class member initializers and = default) is already used elsewhere in the repo, e.g. Svc/DpWriter/DpWriter.hpp, Svc/SeqDispatcher/SeqDispatcher.hpp, Svc/Ccsds/AosFramer/AosFramer.hpp, Svc/Ccsds/ApidManager/ApidManager.hpp.

Testing/Review Recommendations

Behavior is unchanged — this is a refactor of where members are initialized, not what they are initialized to:

  • The previous initializer list initialized members in declaration order (which it must, by C++ rules). The new in-class initializers initialize members in declaration order. Construction order and values are identical.
  • All flagged members were primitive scalars or pointers, all initialized to their natural zero/nullptr value. The new defaults match exactly: bool → false, integer types → 0, pointer types → nullptr.
  • The empty destructor ~DpCatalog() {} is semantically equivalent to ~DpCatalog() = default;.

Local validation:

  • clang-format --dry-run --Werror (clang-format 22) against the repo's .clang-format (Chromium, IndentWidth 4, ColumnLimit 120): passes with exit 0.
  • cppcheck --enable=warning,style,performance --std=c++17 against Svc/DpCatalog/DpCatalog.{cpp,hpp} reports the same two pre-existing style findings (redundantInitialization on response and stat) before and after this change, just shifted by 25 lines because of the line delta. No new findings introduced.
  • Unit tests not modified; this PR introduces no behavior change.

Future Work

The remaining static analysis findings in #4521 — cognitive complexity in fillBinaryTree, nested control flow, reinterpret_cast replacements, std::string migrations, const-correctness on parameters and helpers, unchecked parameter dereferences, etc. — remain untouched and can be tackled in follow-up PRs.

AI Usage (see policy)

Claude Code (Anthropic, model claude-opus-4-7) was used as a pair-programming assistant for the following:

Resolves several static analysis findings from nasa#4521 in Svc/DpCatalog:

- 22x cpp:S3230 ("Do not use the constructor's initializer list for
  data member ...; use the in-class initializer instead"). All scalar
  and pointer members previously initialized in the constructor's
  member-initializer list are now default-initialized in the class
  body of DpCatalog.hpp.

- 1x cpp:S3490 ("Use =default instead of the default implementation
  of this special member function"). The empty destructor is now
  declared = default in the header.

Behavior is unchanged: members are still initialized in declaration
order, which matched the previous initializer-list order, so the
construction sequence is identical. Object members
(m_directories[], m_fileList[], m_stateFile, m_currXmitFileName)
are unchanged because they are default-constructed and were not
flagged by SonarQube.

Aligned with the in-class initializer style already used elsewhere
in the repo (e.g. Svc/DpWriter, Svc/SeqDispatcher,
Svc/Ccsds/AosFramer).
Copilot AI review requested due to automatic review settings April 29, 2026 18:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes Svc::DpCatalog construction/destruction by moving scalar/pointer member initialization from the constructor member-initializer list into in-class default member initializers, and by defaulting the (previously empty) destructor. This aligns DpCatalog with existing in-repo patterns and resolves the referenced SonarQube findings without changing runtime behavior.

Changes:

  • Convert ~DpCatalog() from an empty out-of-line definition to ~DpCatalog() = default; in the header.
  • Replace constructor member-initializer list for scalar/pointer members with in-class default initializers.
  • Simplify the constructor definition to only initialize the base component.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Svc/DpCatalog/DpCatalog.hpp Default the destructor and add in-class default initializers for scalar/pointer members.
Svc/DpCatalog/DpCatalog.cpp Remove the large member-initializer list and the empty destructor definition; keep a minimal constructor delegating to the base.

Comment thread Svc/DpCatalog/DpCatalog.cpp Fixed
Comment thread Svc/DpCatalog/DpCatalog.cpp Fixed
Addresses CodeQL "More than one statement per line" alert introduced by
the previous commit, which collapsed the constructor signature and the
empty body onto the same line. Adds an explanatory comment inside the
body to keep it on its own line; clang-format would otherwise re-collapse
the empty `{}` under the repo's Chromium-based style.

Behavior unchanged.
Comment thread Svc/DpCatalog/DpCatalog.cpp Dismissed
@timcanham
Copy link
Copy Markdown
Collaborator

What version of C++ does this feature rely on?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants