chore: use much more specific CPP feature flags - #6150
Conversation
rwgk
left a comment
There was a problem hiding this comment.
Looks good to me, but could you please extend the PR Description before you merge:
Currently it only describes "What changes", but the "Why" is missing.
The code is becoming (slightly) more complicated / less readable. What makes it worth it?
|
The main benefit is that PYBIND11_CPP14/17 tells us which language mode was selected, while the feature-test macros tell us whether the specific feature the code depends on is actually available. For example, overload_cast specifically requires variable templates, the lambda code requires init-captures, and the out-of-line definitions are specifically fallbacks for the absence of inline variables. Testing those features directly handles partially conforming or feature-backporting compilers more accurately, and also makes the reason for each compatibility branch explicit. For some esoteric compiler settings, this will work while the current code will fail. I agree it is slightly more verbose, though, and on modern compilers there should be little practical difference. |
Description
Suggested changelog entry: