Skip to content

bug: ifdef not supported inside constructor member initializer list #297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
2 tasks done
BrickBee opened this issue Dec 10, 2024 · 0 comments
Open
2 tasks done
Labels

Comments

@BrickBee
Copy link

Did you check existing issues?

  • I have read all the tree-sitter docs if it relates to using the parser
  • I have searched the existing issues of tree-sitter-cpp

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

Playground (0.23.4?)

Describe the bug

An #if / #ifdef / #endif is supported in different lists, but apparently not in the initializer list as it leads to an error. The parser seems to recover from the error though.

Steps To Reproduce/Bad Parse Tree

translation_unit [0, 0] - [7, 0]
  function_definition [0, 0] - [6, 1]
    declarator: function_declarator [0, 0] - [0, 10]
      declarator: qualified_identifier [0, 0] - [0, 8]
        scope: namespace_identifier [0, 0] - [0, 3]
        name: identifier [0, 5] - [0, 8]
      parameters: parameter_list [0, 8] - [0, 10]
    field_initializer_list [1, 1] - [3, 13]
      field_initializer [1, 3] - [1, 12]
        field_identifier [1, 3] - [1, 6]
        argument_list [1, 6] - [1, 12]
          true [1, 7] - [1, 11]
      ERROR [2, 0] - [2, 20]
        identifier [2, 7] - [2, 20]
      field_initializer [3, 3] - [3, 13]
        field_identifier [3, 3] - [3, 6]
        argument_list [3, 6] - [3, 13]
          false [3, 7] - [3, 12]
    ERROR [4, 0] - [4, 6]
    body: compound_statement [5, 0] - [6, 1]

Expected Behavior/Parse Tree

The second field_initializer tree should be below a preproc_ifdef node and the two errors should not appear.

Repro

Bar::Bar()
	: baz(true)
#ifdef TRIGGER_ERROR
	, qux(false)
#endif
{
}
@BrickBee BrickBee added the bug label Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant