Skip to content

Conversation

@rwgk
Copy link
Collaborator

@rwgk rwgk commented Jul 25, 2021

Follow-on to PR #3127, based on results obtained under PR #3125.

The suggested changelog entry will be in the final PR of this cleanup series.

@rwgk rwgk changed the title Adding PYBIND11_COMPAT_BOOL_CAST to appease MSVC 2015 warning C4800. Removing MSVC C4800 from pragma block at the top of pybind11.h Jul 25, 2021
@rwgk rwgk requested review from Skylion007 and henryiii July 26, 2021 00:30
@rwgk rwgk marked this pull request as ready for review July 26, 2021 17:54
}
#endif
if (res == 0 || res == 1) {
value = (bool) res;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not just make these value = res != 0; ? The problem is that (bool) int_value is poor for performance (according to the warning), so we shouldn't be pretending this is okay to cast.

Copy link
Collaborator Author

@rwgk rwgk Jul 26, 2021

Choose a reason for hiding this comment

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

Done. Applied globally. — I was aiming for a robust general solution before, but you're right, we only need specific solutions, and != 0 is simpler and therefore better.

@rwgk rwgk force-pushed the pragma_block_rm_msvc_c4800 branch from cb7965f to 7d7734f Compare July 26, 2021 18:34
@rwgk rwgk force-pushed the pragma_block_rm_msvc_c4800 branch from 7d7734f to eecd3dd Compare July 26, 2021 19:20
@Skylion007
Copy link
Collaborator

There is a clang-tidy check I can add to this PR which enforces this. https://clang.llvm.org/extra/clang-tidy/checks/readability-implicit-bool-conversion.html with allowing pointer to bool conversions should enforce this behavior in the future.

@Skylion007
Copy link
Collaborator

Actually never mind, I can add that in a separate PR as that check is much more strict than this one even is and will touch a lot more code.

@rwgk
Copy link
Collaborator Author

rwgk commented Jul 26, 2021

Actually never mind, I can add that in a separate PR as that check is much more strict than this one even is and will touch a lot more code.

Awesome, I'm glad. Combining (convoluting) things backfires too often. Best to keep things compartmentalized.

@rwgk rwgk merged commit a0f862d into pybind:master Jul 26, 2021
@rwgk rwgk deleted the pragma_block_rm_msvc_c4800 branch July 26, 2021 20:26
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Jul 26, 2021
@rwgk rwgk removed the needs changelog Possibly needs a changelog entry label Jul 26, 2021
henryiii pushed a commit to henryiii/pybind11 that referenced this pull request Jul 29, 2021
…d#3141)

* Adding PYBIND11_COMPAT_BOOL_CAST to appease MSVC 2015 warning C4800.

* Replacing PYBIND11_COMPAT_BOOL_CAST with simpler != 0

* Extra parentheses (almost all compilers failed without these).
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