Skip to content

bug: Parsing error with explicit calls to operator overloads #252

@MarcelRobitaille

Description

@MarcelRobitaille

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)

tree-sitter 0.20.8

Describe the bug

Explicit calls to the function operator= cause a parsing error.

Steps To Reproduce/Bad Parse Tree

(translation_unit ; [0, 0] - [11, 0]
  (class_specifier ; [0, 0] - [3, 1]
    name: (type_identifier) ; [0, 6] - [0, 9]
    body: (field_declaration_list ; [1, 0] - [3, 1]
      (function_definition ; [2, 3] - [2, 46]
        type: (type_identifier) ; [2, 3] - [2, 6]
        declarator: (reference_declarator ; [2, 6] - [2, 35]
          (function_declarator ; [2, 8] - [2, 35]
            declarator: (operator_name) ; [2, 8] - [2, 17]
            parameters: (parameter_list ; [2, 17] - [2, 35]
              (parameter_declaration ; [2, 18] - [2, 34]
                type: (type_identifier) ; [2, 18] - [2, 21]
                (type_qualifier) ; [2, 22] - [2, 27]
                declarator: (reference_declarator ; [2, 28] - [2, 34]
                  (identifier)))))) ; [2, 29] - [2, 34]
        (default_method_clause)))) ; [2, 36] - [2, 46]
  (function_definition ; [5, 0] - [10, 1]
    type: (primitive_type) ; [5, 0] - [5, 3]
    declarator: (function_declarator ; [5, 4] - [5, 10]
      declarator: (identifier) ; [5, 4] - [5, 8]
      parameters: (parameter_list)) ; [5, 8] - [5, 10]
    body: (compound_statement ; [6, 0] - [10, 1]
      (declaration ; [7, 3] - [7, 14]
        type: (type_identifier) ; [7, 3] - [7, 6]
        declarator: (init_declarator ; [7, 7] - [7, 13]
          declarator: (identifier) ; [7, 7] - [7, 11]
          value: (initializer_list))) ; [7, 11] - [7, 13]
      (declaration ; [8, 3] - [8, 14]
        type: (type_identifier) ; [8, 3] - [8, 6]
        declarator: (init_declarator ; [8, 7] - [8, 13]
          declarator: (identifier) ; [8, 7] - [8, 11]
          value: (initializer_list))) ; [8, 11] - [8, 13]
      (expression_statement ; [9, 3] - [9, 26]
        (call_expression ; [9, 3] - [9, 25]
          function: (identifier) ; [9, 3] - [9, 7]
          (ERROR ; [9, 7] - [9, 18]
            (operator_name)) ; [9, 8] - [9, 18]
          arguments: (argument_list ; [9, 19] - [9, 25]
            (identifier))))))) ; [9, 20] - [9, 24]

Expected Behavior/Parse Tree

The call to operator=() is correctly recognized.

Repro

class Foo
{
   Foo& operator=(Foo const &other) = default;
};

int main()
{
   Foo foo1{};
   Foo foo2{};
   foo1.operator = (foo2);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions