Uh oh!
There was an error while loading. Please reload this page.
Use defined for PYBIND11_HAS_OPTIONAL, PYBIND11_HAS_EXP_OPTIONAL, PYBIND11_HAS_VARIANT - #2476
Conversation
henryiii
commented
Sep 10, 2020
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 |
YannickJadoul
commented
Sep 10, 2020
We're detecting and defining this ourselves, now, so... I don't think this is documented/meant to be set from the outside? |
henryiii
commented
Sep 10, 2020
Probably okay, then. We need to change several |
YannickJadoul
commented
Sep 10, 2020
(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? :-) |
cirosantilli2
commented
Sep 10, 2020
I've updated the PR to update |
henryiii
commented
Sep 10, 2020
Your warning addition should spot them 👍 |
henryiii
commented
Sep 10, 2020
|
YannickJadoul
commented
Sep 10, 2020
@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 | ^~~~~~~~~~~~~~~~~~~~ ```
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: