Skip to content

bug: Parsing error in "typeid(struct X)" #343

@clashman

Description

@clashman

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.25.10

Describe the bug

tree-sitter errors on "typeid(struct X)"

Steps To Reproduce/Bad Parse Tree

(translation_unit [0, 0] - [9, 0]
  (preproc_include [0, 0] - [1, 0]
    path: (system_lib_string [0, 9] - [0, 14]))
  (preproc_include [1, 0] - [2, 0]
    path: (system_lib_string [1, 9] - [1, 20]))
  (struct_specifier [3, 0] - [3, 11]
    name: (type_identifier [3, 7] - [3, 8])
    body: (field_declaration_list [3, 9] - [3, 11]))
  (function_definition [5, 0] - [8, 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 [5, 11] - [8, 1]
      (declaration [6, 2] - [6, 30]
        type: (qualified_identifier [6, 2] - [6, 27]
          scope: (namespace_identifier [6, 2] - [6, 5])
          name: (template_type [6, 7] - [6, 27]
            name: (type_identifier [6, 7] - [6, 10])
            arguments: (template_argument_list [6, 10] - [6, 27]
              (type_descriptor [6, 11] - [6, 26]
                type: (qualified_identifier [6, 11] - [6, 26]
                  scope: (namespace_identifier [6, 11] - [6, 14])
                  name: (type_identifier [6, 16] - [6, 26]))))))
        declarator: (identifier [6, 28] - [6, 29]))
      (expression_statement [7, 2] - [7, 27]
        (call_expression [7, 2] - [7, 26]
          function: (field_expression [7, 2] - [7, 8]
            argument: (identifier [7, 2] - [7, 3])
            field: (field_identifier [7, 4] - [7, 8]))
          arguments: (argument_list [7, 8] - [7, 26]
            (call_expression [7, 9] - [7, 25]
              function: (identifier [7, 9] - [7, 15])
              arguments: (argument_list [7, 15] - [7, 25]
                (identifier [7, 16] - [7, 22])
                (ERROR [7, 23] - [7, 24]
                  (identifier [7, 23] - [7, 24]))))))))))
../foo.cpp	Parse:    6.57 ms	    19 bytes/ms	(ERROR [7, 23] - [7, 24])

Expected Behavior/Parse Tree

This compiles without any warning or error, so tree-sitter should be able to handle it.

Repro

#include <set>
#include <typeindex>

struct X {};

int main() {
  std::set<std::type_index> s;
  s.find(typeid(struct X));
}

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