-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Use defined for PYBIND11_HAS_OPTIONAL, PYBIND11_HAS_EXP_OPTIONAL, PYBIND11_HAS_VARIANT #2476
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
Conversation
67dd258
to
29acfc0
Compare
Note this changes the behavior; defining this to 0 causes it to be used now, instead of skipped. A completely backward compatible version would be |
We're detecting and defining this ourselves, now, so... I don't think this is documented/meant to be set from the outside? |
Probably okay, then. We need to change several |
(Just wait for @bstaletic to pop up and shout about Hyrum's law, though.) But another argument: pybind11's code detecting it also doesn't check if something is already defined: pybind11/include/pybind11/stl.h Lines 27 to 49 in fbc7563
So if someone manually defines it, it's 1) overwrtiten (I think ?), and 2) likely gives some warning. So even considering a mild version of Hyrum's law, we should be fine? :-) Would you mind having a look for the other macros that @henryiii mentions, and adding them to this PR, @cirosantilli2? :-) |
29acfc0
to
ec4e47c
Compare
I've updated the PR to update |
Your warning addition should spot them 👍 |
|
@cirosantilli2 If I'm not mistaken, warnings are treated as errors in the CI builds. So just follow the smell of the warnings/errors ;-) |
The variables PYBIND11_HAS_OPTIONAL, PYBIND11_HAS_EXP_OPTIONAL, PYBIND11_HAS_VARIANT, __clang__, __APPLE__ were not checked for defined in a minortity of instances. If the project using pybind11 sets -Wundef, the warnings will show. The test build is also modified to catch the problem. The errors looked like: ``` ext/pybind11/include/pybind11/stl.h:292:5: error: "PYBIND11_HAS_OPTIONAL" is not defined, evaluates to 0 [-Werror=undef] 292 | #if PYBIND11_HAS_OPTIONAL | ^~~~~~~~~~~~~~~~~~~~~ ext/pybind11/include/pybind11/stl.h:300:5: error: "PYBIND11_HAS_EXP_OPTIONAL" is not defined, evaluates to 0 [-Werror=undef] 300 | #if PYBIND11_HAS_EXP_OPTIONAL | ^~~~~~~~~~~~~~~~~~~~~~~~~ ext/pybind11/include/pybind11/stl.h:372:5: error: "PYBIND11_HAS_VARIANT" is not defined, evaluates to 0 [-Werror=undef] 372 | #if PYBIND11_HAS_VARIANT | ^~~~~~~~~~~~~~~~~~~~ ```
ec4e47c
to
52a281c
Compare
These variables are not set in certain circumstances, and if the project
using pybind11 sets -Wundef, the warnings will show.
In all other usages outside of stl.h, ifdef/defined has already been used,
this commit converts the remaining ones under stl.h.
The test build is also modified to catch the problem.
The errors looked like: