-
-
Notifications
You must be signed in to change notification settings - Fork 131
Open
Labels
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
)
https://tree-sitter.github.io/tree-sitter/7-playground.html
Describe the bug
Incorrect parsing tree for variadic template function with pointer arguments.
Consider this snippet of code:
template <typename... Arg>
void Method(Arg *...args)
{
(MethodImpl(args), ...);
}
Arg *...args
is parsed as binary expression and overall syntax tree for this function definition gets messed up.
Hopefully this can be parsed with less breaking error. Thank you!
Steps To Reproduce/Bad Parse Tree
translation_unit [0, 0] - [5, 0]
template_declaration [0, 0] - [1, 25]
parameters: template_parameter_list [0, 9] - [0, 26]
variadic_type_parameter_declaration [0, 10] - [0, 25]
type_identifier [0, 22] - [0, 25]
declaration [1, 0] - [1, 25]
type: primitive_type [1, 0] - [1, 4]
declarator: init_declarator [1, 5] - [1, 25]
declarator: identifier [1, 5] - [1, 11]
value: argument_list [1, 11] - [1, 25]
binary_expression [1, 12] - [1, 24]
left: identifier [1, 12] - [1, 15]
ERROR [1, 17] - [1, 20]
right: identifier [1, 20] - [1, 24]
MISSING ";" [1, 25] - [1, 25]
compound_statement [2, 0] - [4, 1]
expression_statement [3, 4] - [3, 28]
fold_expression [3, 4] - [3, 27]
left: call_expression [3, 5] - [3, 21]
function: identifier [3, 5] - [3, 15]
arguments: argument_list [3, 15] - [3, 21]
identifier [3, 16] - [3, 20]
Expected Behavior/Parse Tree
Expected to parse to function_definition
translation_unit [0, 0] - [5, 0]
template_declaration [0, 0] - [4, 1]
parameters: template_parameter_list [0, 9] - [0, 26]
variadic_type_parameter_declaration [0, 10] - [0, 25]
type_identifier [0, 22] - [0, 25]
function_definition [1, 0] - [4, 1]
type: primitive_type [1, 0] - [1, 4]
declarator: function_declarator [1, 5] - [1, 25]
declarator: identifier [1, 5] - [1, 11]
parameters: parameter_list [1, 11] - [1, 25]
variadic_parameter_declaration [1, 12] - [1, 24]
type: type_identifier [1, 12] - [1, 15]
declarator: pointer_declarator [1, 16] - [1, 24]
variadic_declarator [1, 17] - [1, 24]
identifier [1, 20] - [1, 24]
body: compound_statement [2, 0] - [4, 1]
expression_statement [3, 4] - [3, 28]
fold_expression [3, 4] - [3, 27]
left: call_expression [3, 5] - [3, 21]
function: identifier [3, 5] - [3, 15]
arguments: argument_list [3, 15] - [3, 21]
identifier [3, 16] - [3, 20]
Repro
template <typename Arg>
void MethodImpl(Arg *args)
{ /* ... */ }
// Code that fails to parse, or causes an error
template <typename... Arg>
void Method(Arg *...args)
{
(MethodImpl(args), ...);
}
int main() {
return 0;
}