Skip to content

Use C++20 requires clauses in TypeNameGeneratorBase#8552

Open
sbc100 wants to merge 1 commit intomainfrom
wasm-type-printing
Open

Use C++20 requires clauses in TypeNameGeneratorBase#8552
sbc100 wants to merge 1 commit intomainfrom
wasm-type-printing

Conversation

@sbc100
Copy link
Copy Markdown
Member

@sbc100 sbc100 commented Mar 30, 2026

This addresses the TODOs in src/wasm-type-printing.h by utilizing C++20 concepts and requires clauses.

  • Replaced the manual SFINAE/macro-based check in TypeNameGeneratorBase with a static_assert(requires { ... }) to ensure subclasses implement getNames correctly. This is cleaner and more robust.
  • Updated the ModuleTypeNameGenerator constructor to use a requires clause instead of std::enable_if_t for its default constructor, improving readability.
  • Added #include as required.

This addresses the TODOs in src/wasm-type-printing.h by utilizing C++20
concepts and requires clauses.

- Replaced the manual SFINAE/macro-based check in TypeNameGeneratorBase
  with a static_assert(requires { ... }) to ensure subclasses implement
  getNames correctly. This is cleaner and more robust.
- Updated the ModuleTypeNameGenerator constructor to use a requires
  clause instead of std::enable_if_t for its default constructor,
  improving readability.
- Added #include <concepts> as required.
@sbc100 sbc100 requested a review from a team as a code owner March 30, 2026 23:55
@sbc100 sbc100 requested review from tlively and removed request for a team March 30, 2026 23:55
@sbc100
Copy link
Copy Markdown
Member Author

sbc100 commented Mar 30, 2026

The plan is to do a release of binaryen with C++20 set and let it bake for a couple of weeks at least before landing stuff like this.

This change was 100% gemini created BTW.

@sbc100 sbc100 requested review from tlively and removed request for tlively March 30, 2026 23:56
Copy link
Copy Markdown
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that's nice. Did you check that the assertions fail properly when you introduce errors? How do the error messages look?

@sbc100
Copy link
Copy Markdown
Member Author

sbc100 commented Mar 31, 2026

Oh that's nice. Did you check that the assertions fail properly when you introduce errors? How do the error messages look?

Nope.. I just told gemini to fix the TODOs. I'm a little scared that I will never learn new things like this since I'm not being forces to write them.

I'll circle back in a week or two once the C++20 dust has settled.

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.

2 participants