-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CodeHealth: Enabling clang-tidy google-explicit-constructor #3250
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Skylion007
approved these changes
Sep 8, 2021
Thanks Aaron! I added a small paragraph for the upgrade guide to the PR description. |
rwgk
pushed a commit
to rwgk/pybind11
that referenced
this pull request
Sep 9, 2021
rwgk
pushed a commit
to rwgk/pybind11
that referenced
this pull request
Sep 9, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The main change is the one-line addition of
google-explicit-constructor
in .clang-tidy:https://clang.llvm.org/extra/clang-tidy/checks/google-explicit-constructor.html
This enforces the use of
explicit
, unless disabled withNOLINT
. In other words, bug-prone implicit conversions are made opt-in rather than opt-out.Apart from the entertaining
#ifdef
in include/pybind11/functional.h, the rest of this PR is extremely dull. It is the result of ~20 iterations of running clang-tidy, and manually sorting through the automatic changes, insertingas needed. Final change stats are:
explicit
added under include/pybind11/NOLINT
added under include/pybind11/explicit
added under tests/NOLINT
added under tests/The only code changes beyond these are in tests/test_smart_ptr.cpp, one of them
and two similar changes.
It is possible that some
NOLINT
under include/pybind11/ could be removed, with corresponding code changes elsewhere, but those are likely more involved and best left for separate PRs, so that they don't get drowned in the sea of boilerplate changes under this PR.Suggested changelog entry:
The clang-tidy ``google-explicit-constructor`` option was enabled.
PR #3250 added a number of
explicit
keywords to improve general code health. It is not expected that this affects user code, but it is a possibility. Insert explicit constructors in your code as needed, or if that is not feasible, please send a PR to replace the problematicexplicit
keywords with// NOLINTNEXTLINE(google-explicit-constructor)
directives, including a unit test reflecting your use case.