Skip to content

Removing MSVC C4800 from pragma block at the top of pybind11.h - #3141

Merged
rwgk merged 3 commits into
pybind:masterfrom
rwgk:pragma_block_rm_msvc_c4800
Jul 26, 2021
Merged

Removing MSVC C4800 from pragma block at the top of pybind11.h#3141
rwgk merged 3 commits into
pybind:masterfrom
rwgk:pragma_block_rm_msvc_c4800

Conversation

@rwgk

@rwgkrwgk commented Jul 25, 2021

Copy link
Copy Markdown
Collaborator

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.

@rwgkrwgk 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.hJul 25, 2021
@rwgk
rwgk requested review from Skylion007 and henryiiiJuly 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
Copy Markdown
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.

@rwgkrwgkJul 26, 2021

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.

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
rwgkforce-pushed the pragma_block_rm_msvc_c4800 branch from cb7965f to 7d7734fCompareJuly 26, 2021 18:34
@rwgk
rwgkforce-pushed the pragma_block_rm_msvc_c4800 branch from 7d7734f to eecd3ddCompareJuly 26, 2021 19:20
@Skylion007

Copy link
Copy Markdown
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
Copy Markdown
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

rwgk commented Jul 26, 2021

Copy link
Copy Markdown
CollaboratorAuthor

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:masterJul 26, 2021
@rwgk
rwgk deleted the pragma_block_rm_msvc_c4800 branch July 26, 2021 20:26
@github-actionsgithub-actionsBot added the needs changelog Possibly needs a changelog entry label Jul 26, 2021
@rwgkrwgk 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).
@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

@rwgk@Skylion007@henryiii