Skip to content

Conversation

@rktdm
Copy link
Contributor

@rktdm rktdm commented Sep 6, 2025

Three commits here for three really huge c++26 features. Included corpus tests that pull most of the examples from the ISO papers themselves.

P2996: reflection

This adds support for all the language changes introduced in P2996 which
was recently voted into the upcoming c++26 standard.

This includes:

  • reflection expressions: the reflect operator (^^) followed by
    expressions, type descriptors, or the global namespace (::)
  • splice specifiers/expressions: [: expression :], which can appear as a
    type, expression, alias descriptor, and more.
  • consteval blocks: similar to static_asserts but have been introduced
    specifically to allow constant evaluation side effects to occur at
    specific places in code

P3394: annotations

Related to reflection, annotations use the same syntax as attributes,
but begin with an = and support any constant expression. Annotations
and Attributes can't be mixed within [[ ... ]].

P1306: expansion statements

Introduces support for template for ( init; for-range-decl : expansion-init )
which is a compile-time way to expand (iterate over):

  • expansion expressions
  • anything destructurable via structured bindings
  • ranges with compile time size

It was sufficient to simply re-use the existing rule for
_for_range_loop_body for the part inside the parentheses, but add the
required sequence of template followed by for

@rktdm rktdm force-pushed the reflection branch 2 times, most recently from e593da8 to fec98f7 Compare September 6, 2025 16:21
@jdrouhard
Copy link
Collaborator

Wow, this is exciting. Reflection is going to be amazing. Thanks for getting on this so quickly!

I merged another PR in front of this one so I'm going to rebase and regenerate.

This adds support for all the language changes introduced in P2996 which
was recently voted into the upcoming c++26 standard.

This includes:
- reflection expressions: the reflect operator (^^) followed by
  expressions, type descriptors, or the global namespace (::)
- splice specifiers/expressions: [: expression :], which can appear as a
  type, expression, alias descriptor, and more.
- consteval blocks: similar to static_asserts but have been introduced
  specifically to allow constant evaluation side effects to occur at
  specific places in code
Related to reflection, annotations use the same syntax as attributes,
but begin with an `=` and support any constant expression. Annotations
and Attributes can't be mixed within [[ ... ]].
Introduces support for `template for ( init; for-range-decl : expansion-init )`
which is a compile-time way to expand (iterate over):
  - expansion expressions
  - anything destructurable via structured bindings
  - ranges with compile time size

It was sufficient to simply re-use the existing rule for
_for_range_loop_body for the part inside the parentheses, but add the
required sequence of `template` followed by `for`
@jdrouhard jdrouhard merged commit 12bd6f7 into tree-sitter:master Sep 27, 2025
4 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.

2 participants