Skip to content

[ast-match] Add isAggregate and isFullyDesignated AST matchers#12

Merged
hach-que merged 1 commit intoredpoint/18.xfrom
aggregate
Feb 14, 2025
Merged

[ast-match] Add isAggregate and isFullyDesignated AST matchers#12
hach-que merged 1 commit intoredpoint/18.xfrom
aggregate

Conversation

@hach-que
Copy link
Member

@hach-que hach-que commented Feb 14, 2025

These new AST matchers allow you to build a rule like this:

Rules:
- # Find initializers that are undesignated (requires C++20)
  Name: use-designated-init
  Matcher: |
    initListExpr(
      hasType(
        cxxRecordDecl(
          isAggregate(),
          matchesName("::Redpoint::EOS::API::*"),
          unless(hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl())))))
        ).bind("type")
      ),
      unless(isFullyDesignated())
    ).bind("init")
  ErrorMessage: |
    initializer list should be fully designated
  Callsite: init

This detects any scenario where a value is initialized like SomeType{4, 5} when it should be initialized with SomeType{.A = 4, .B = 5} using the designated initializer list language feature of C++20.

@hach-que hach-que enabled auto-merge (squash) February 14, 2025 01:39
@hach-que hach-que merged commit cddb8dc into redpoint/18.x Feb 14, 2025
4 checks passed
@hach-que hach-que deleted the aggregate branch February 14, 2025 04:10
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