Skip to content

refs #14498 - do not create global static instances of the checks - #8555

Merged
firewave merged 3 commits into
cppcheck-opensource:mainfrom
firewave:inst
May 16, 2026
Merged

refs #14498 - do not create global static instances of the checks#8555
firewave merged 3 commits into
cppcheck-opensource:mainfrom
firewave:inst

Conversation

@firewave

Copy link
Copy Markdown
Collaborator

No description provided.

@firewave

Copy link
Copy Markdown
CollaboratorAuthor

Since we switched to non-OBJECT library everything which links against lib will instantiate all checks even if never used (i.e. dmake). This changes the code only instantiate them if they are actually requested.

As a follow-up we can stop relying on the global check instances in the tests and use local ones instead. As a final step this will (hopefully) finally allow us to land #5323.

Comment threadlib/check.h Outdated
Check& operator=(const Check &) = delete;

/** List of registered check classes. This is used by Cppcheck to run checks and generate documentation */
static std::list<Check *> &instances();

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

As another positive side effect this no longer needs to return a mutable reference.

Comment threadtest/testcheck.cpp

private:
void run() override {
TEST_CASE(instancesSorted);

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

As we now have a fixed order of the checks there no longer is any reason to sort them.

@firewave
firewaveforce-pushed the inst branch 3 times, most recently from e29a0c1 to 34f7be7CompareMay 14, 2026 10:00
Comment threadlib/checks.cpp Fixed
Comment threadlib/checks.cpp Fixed
Comment threadlib/checks.cpp Fixed
Comment threadlib/checks.cpp Fixed
Comment threadlib/cppcheck.cpp Fixed
@firewave
firewaveforce-pushed the inst branch 2 times, most recently from ab5d808 to d6d29c5CompareMay 14, 2026 12:09
@firewavefirewave changed the title refs #14498 - do not create static instances of the checksrefs #14498 - do not create global static instances of the checksMay 14, 2026
Comment threadlib/checks.cpp Dismissed
Comment threadlib/checks.cpp
{
private:
/* *INDENT-OFF* */
#define UPI(c) std::unique_ptr<c> m##c{new c}
Comment threadlib/checks.cpp Dismissed
Comment threadlib/checks.cpp Dismissed
@firewave
firewave marked this pull request as ready for review May 15, 2026 16:20
@firewave

Copy link
Copy Markdown
CollaboratorAuthor

Maybe someone can come up with an improved macro that would also build the list so we only need to specify the check name once. Could also be done in a follow-up since I have other changes already lined up.

@danmardanmar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Alright. I wanted from the start that checks are dynamic so it would be possible to link extra checker classes dynamically. I.e. users could develop custom checkers.
But checkers will never be linked dynamically in that way so we can as well do this.

@firewave
firewave merged commit f7f0549 into cppcheck-opensource:mainMay 16, 2026
70 checks passed
@firewave
firewave deleted the inst branch May 16, 2026 14:01
@firewave

Copy link
Copy Markdown
CollaboratorAuthor

Alright. I wanted from the start that checks are dynamic so it would be possible to link extra checker classes dynamically. I.e. users could develop custom checkers. But checkers will never be linked dynamically in that way so we can as well do this.

I think that plan was superseded by the addons. Even if that functionality would be added those can still be dynamically added to the list - should be even more possible then before when the object creation wasn't controlled.

Sign up for freeto 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.

3 participants

@firewave@danmar@github-advanced-security