Skip to content

feat(dsl): allow block-scope PTN_BIND names inside PTN_ON - #49

Merged
sentomk merged 1 commit into
mainfrom
feat/ptn-on-block-scope-names
Aug 1, 2026
Merged

feat(dsl): allow block-scope PTN_BIND names inside PTN_ON#49
sentomk merged 1 commit into
mainfrom
feat/ptn-on-block-scope-names

Conversation

@sentomk

@sentomk sentomk commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Summary

Block-scope PTN_BIND declarations can now be referenced inside PTN_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 declarations static storage duration. PTN_ON itself is unchanged.

Changes

  • PTN_BIND_DECL now expands to static 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_ON caveat (added in feat(guard): anchor PTN_BIND names to members #47) with the new guarantee.

Testing

  • New tests BlockScopeNamesWorkInsidePtnOn and RepeatedNamesInsidePtnOn: arithmetic guards with repeated names inside PTN_ON, including a second call exercising the cached static case pack. Verified with GCC 13 + Clang 20 in C++17 mode.
  • Full suite: 195/195 passing.
  • The static_on_with_capture compile-fail guard still passes — PTN_ON's captureless design is untouched.

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

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@sentomk
sentomk merged commit cc48b3f into main Aug 1, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant