Skip to content

chore: use much more specific CPP feature flags - #6150

Merged
rwgk merged 1 commit into
pybind:masterfrom
Skylion007:skylion007/use-more-cpp-feature-flags-2026-08-21
Aug 25, 2026
Merged

chore: use much more specific CPP feature flags#6150
rwgk merged 1 commit into
pybind:masterfrom
Skylion007:skylion007/use-more-cpp-feature-flags-2026-08-21

Conversation

@Skylion007

Copy link
Copy Markdown
Collaborator

Description

  • Narrows a bunch of previously broad CPP version guards to just the feature macros they need to compile.

Suggested changelog entry:

  • Narrow CPP version guards to minimum require CPP feature macros

@Skylion007
Skylion007 requested a review from henryiii August 21, 2026 17:19
@Skylion007 Skylion007 changed the title (BE)(NFC): Use much more specific CPP feature flags chore: Use much more specific CPP feature flags Aug 21, 2026
@Skylion007 Skylion007 changed the title chore: Use much more specific CPP feature flags chore: use much more specific CPP feature flags Aug 21, 2026

@rwgk rwgk left a comment

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.

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?

@Skylion007

Copy link
Copy Markdown
Collaborator Author

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.

@rwgk
rwgk merged commit 5e9611a into pybind:master Aug 25, 2026
78 checks passed
@github-actions github-actions Bot added the needs changelog Possibly needs a changelog entry label Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs changelog Possibly needs a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants