Skip to content
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
merged 26 commits into from
Sep 9, 2021

Conversation

rwgk
Copy link
Collaborator

@rwgk rwgk commented Sep 8, 2021

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 with NOLINT. 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, inserting

// NOLINTNEXTLINE(google-explicit-constructor)

as needed. Final change stats are:

  • 27 explicit added under include/pybind11/
  • 46 NOLINT added under include/pybind11/
  • 92 explicit added under tests/
  • 0 NOLINT added under tests/

The only code changes beyond these are in tests/test_smart_ptr.cpp, one of them

-    m.def("make_object_2", []() -> ref<Object> { return new MyObject1(2); });
+    m.def("make_object_2", []() -> ref<Object> { return ref<Object>(new MyObject1(2)); });

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 problematic explicit keywords with // NOLINTNEXTLINE(google-explicit-constructor) directives, including a unit test reflecting your use case.

Ralf W. Grosse-Kunstleve added 26 commits September 7, 2021 15:18
@rwgk rwgk marked this pull request as ready for review September 8, 2021 21:31
@rwgk rwgk requested a review from henryiii as a code owner September 8, 2021 21:31
@rwgk rwgk requested a review from Skylion007 September 8, 2021 21:31
@rwgk
Copy link
Collaborator Author

rwgk commented Sep 9, 2021

Thanks Aaron!

I added a small paragraph for the upgrade guide to the PR description.

@rwgk rwgk merged commit 6abf2ba into pybind:master Sep 9, 2021
@rwgk rwgk deleted the clang_tidy_explicit branch September 9, 2021 01:53
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Sep 9, 2021
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
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Sep 16, 2021
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.

3 participants