Skip to content

bug: Parse error with variadic template function that takes pointers as arguments #318

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
bahbyega opened this issue May 29, 2025 · 0 comments
Open
2 tasks done
Labels

Comments

@bahbyega
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)

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;
}
@bahbyega bahbyega added the bug label May 29, 2025
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