tree-sitter / tree-sitter/tree-sitter-cpp

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

Open
#343 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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)

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));
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided C++ reproduction with the Tree-Sitter CLI and inspect the parse tree around typeid(struct X), especially the ERROR node. Trace the C++ grammar rule handling typeid arguments and add or update a focused parser test; done means the reproduction parses without an ERROR node while preserving the expected structure.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.