Skip to content

fix(clang-tidy): Enable clang-tidy else-after-return and redundant void checks - #3080

Merged
rwgk merged 6 commits into
pybind:masterfrom
Skylion007:clang-tidy-readability-else-after
Jul 9, 2021
Merged

fix(clang-tidy): Enable clang-tidy else-after-return and redundant void checks#3080
rwgk merged 6 commits into
pybind:masterfrom
Skylion007:clang-tidy-readability-else-after

Conversation

@Skylion007

@Skylion007Skylion007 commented Jul 7, 2021

Copy link
Copy Markdown
Collaborator

Description

  • Clang-Tidy enable a few useful fixes:
  • VirtualCalls (Check that Virtual Calls are not called in the constructor in the destructor ( they can be called if fully qualified, but they cannot be overridden during construction and destruction). This checks makes it very clear. Luckily, this behavior isn't used anywhere in the codebase, but this check will guard against it.
  • Removes redundant void arguments.
  • Most importantly removes all else-after-returns in the code base and prevents new code from introducing it. This is better style and a part of LLVM Style.

Suggested changelog entry:

* Add clang-tidy checks to further guard code style and remove all else after returns for better code readability. Also encourages following llvm-style (no ``else-after-returns``, proper usage of virtual functions in ctors and dtors).

rwgk
rwgk approved these changes Jul 7, 2021

@rwgkrwgk 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.

Awesome :-)

Comment threadinclude/pybind11/cast.h Outdated
@@ -555,9 +563,8 @@ template <template<typename...> class Tuple, typename... Ts> class tuple_caster
if (!src) return none().release();
if (policy == return_value_policy::take_ownership) {
auto h = cast(std::move(*src), policy, parent); delete src; return h;

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.

Could you please also move the delete and return to separate lines while you're at it?
I had to squint at this for a while until I finally noticed the return h;

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.

@rwgk Done.

@Skylion007

Copy link
Copy Markdown
CollaboratorAuthor

Since I can't assign reviewers yet, ping @henryiii

@Skylion007

Copy link
Copy Markdown
CollaboratorAuthor

ReOpen to retrigger

@Skylion007Skylion007 reopened this Jul 8, 2021
@rwgk

rwgk commented Jul 9, 2021

Copy link
Copy Markdown
Collaborator

@henryiii in the meantime I ran this through the Google-global testing: no issues.
Considering that you wrote "I like what I saw" and that this is a pure code health PR that's hardening our CI, I'll go ahead merging so we can move forward with other things.

@rwgk
rwgk merged commit b5357d1 into pybind:masterJul 9, 2021
@github-actionsgithub-actionsBot added the needs changelog Possibly needs a changelog entry label Jul 9, 2021
rwgk added a commit that referenced this pull request Jul 9, 2021
rwgk added a commit to rwgk/pybind11 that referenced this pull request Jul 9, 2021
…r the just-merged PR pybind#3080. Also rerunning clang-format-diff.py to pick up a few fixes missed before.
@Skylion007
Skylion007 deleted the clang-tidy-readability-else-after branch July 12, 2021 20:38
@henryiiihenryiii removed the needs changelog Possibly needs a changelog entry label Jul 13, 2021
@rwgkrwgk mentioned this pull request Feb 10, 2023
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

@Skylion007@rwgk@henryiii