Skip to content

Comments

OpenPMDWriter.cpp & HpMultiGrid.H : enforce clang-tidy rule bugprone-branch-clone#1304

Merged
AlexanderSinn merged 2 commits intoHi-PACE:developmentfrom
lucafedeli88:enforce_bugprone_branch_clone
Oct 29, 2025
Merged

OpenPMDWriter.cpp & HpMultiGrid.H : enforce clang-tidy rule bugprone-branch-clone#1304
AlexanderSinn merged 2 commits intoHi-PACE:developmentfrom
lucafedeli88:enforce_bugprone_branch_clone

Conversation

@lucafedeli88
Copy link
Contributor

This PR is a follow-up of #1302 .
By using the tool proposed in #1303 I ran clang-tidy on the code. This PR fixes the issues found with the rule:

Is this something that you would like to enforce in HiPACE++ ? In my opinion, most of the checks of the bugprone-* family are quite useful (in WarpX we decided to enable most of them)...

These are the only issues found with the following rules:

    bugprone-argument-comment,
    bugprone-assert-side-effect,
    bugprone-assignment-in-if-condition,
    bugprone-bad-signal-to-kill-thread,
    bugprone-bitwise-pointer-cast,
    bugprone-bool-pointer-implicit-conversion,
    bugprone-branch-clone,
    bugprone-casting-through-void,
    bugprone-chained-comparison,
    bugprone-compare-pointer-to-member-virtual-function,
    bugprone-copy-constructor-init,
    bugprone-crtp-constructor-accessibility,
    bugprone-dangling-handle,
    bugprone-dynamic-static-initializers,
    cppcoreguidelines-avoid-goto
  • Small enough (< few 100s of lines), otherwise it should probably be split into smaller PRs
  • Tested (describe the tests in the PR description)
  • Runs on GPU (basic: the code compiles and run well with the new module)
  • Contains an automated test (checksum and/or comparison with theory)
  • Documented: all elements (classes and their members, functions, namespaces, etc.) are documented
  • Constified (All that can be const is const)
  • Code is clean (no unwanted comments, )
  • Style and code conventions are respected at the bottom of https://github.com/Hi-PACE/hipace
  • Proper label and GitHub project, if applicable

Comment on lines +183 to +187
case 1:
case 2:
return 2;
case 3:
return 1;
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I feel like the old way is more readable as it looks closer to get_num_comps_acf below it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you want uniformity of style, one option would be to change also get_num_comps_acf by writing:

switch (system_type) {
    case 1:
        return 1;
    case 2:
        return 2;
    case 3:
        return 0;
}

There's also the option of disregarding the rule if you don't like it.

Copy link
Member

Choose a reason for hiding this comment

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

I discussed this with Emanuele on what is more readable, and it is ok to do it the clang-tidy way if also the formatting in get_num_comps_acf is updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Member

@AlexanderSinn AlexanderSinn left a comment

Choose a reason for hiding this comment

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

Thanks for this PR!

@AlexanderSinn AlexanderSinn merged commit 5068017 into Hi-PACE:development Oct 29, 2025
9 of 10 checks passed
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.

2 participants