tree-sitter / tree-sitter/tree-sitter-cpp
bug: ifdef not supported inside constructor member initializer list
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 453
- Forks
- 185
- PR merge metrics
- No merged PRs in 30d
Description
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
{
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the C++ reproduction in the issue and compare its actual parse tree with the expected tree, focusing on the field_initializer_list and preprocessor directives. Trace the tree-sitter-cpp grammar path for constructor member initializers and add a regression case whose parse tree contains a preproc_ifdef node without the reported ERROR nodes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100