feat(dsl): allow block-scope PTN_BIND names inside PTN_ON - #49
Merged
Conversation
Problem - Block-scope PTN_BIND declarations could not be referenced inside PTN_ON: its caching lambda is captureless by design, and passing a placeholder to guard operators odr-used it, forcing a capture. - Single use sometimes slipped through, but using the same name twice in one expression (x * x == y * y) failed on GCC and Clang. Implementation - Give PTN_BIND declarations static storage duration. Captures are only required for automatic variables, so statics are freely usable inside the captureless lambda, for any expression shape. - PTN_ON itself is unchanged; its captureless design (and the static_on_with_capture compile-fail guard) stays intact. Tests - Add BlockScopeNamesWorkInsidePtnOn and RepeatedNamesInsidePtnOn covering arithmetic guards with repeated names and the cached second call; full suite: 195/195 (GCC 13 + Clang 20, C++17). - docs/api.md: replace the former block-scope/PTN_ON caveat with the new guarantee.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Block-scope
PTN_BINDdeclarations can now be referenced insidePTN_ON. Previously this failed to compile:PTN_ON's caching lambda is captureless by design, and passing a placeholder to the guard operators odr-used it, forcing a capture. The fix is one word — give the declarationsstaticstorage duration.PTN_ONitself is unchanged.Changes
PTN_BIND_DECLnow expands tostatic constexpr member_t<&Type::name>. Captures are only required for automatic variables, so statics are freely usable inside the captureless lambda — for any expression shape, including repeated names (x * x == y * y), which failed on both GCC and Clang before.docs/api.md: replace the former block-scope/PTN_ONcaveat (added in feat(guard): anchor PTN_BIND names to members #47) with the new guarantee.Testing
BlockScopeNamesWorkInsidePtnOnandRepeatedNamesInsidePtnOn: arithmetic guards with repeated names insidePTN_ON, including a second call exercising the cached static case pack. Verified with GCC 13 + Clang 20 in C++17 mode.static_on_with_capturecompile-fail guard still passes —PTN_ON's captureless design is untouched.