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

bug: Macro prefix to local variable creation leads to "missing semicolon"

Open
#300 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)

Playground (0.23.4?)

Describe the bug

Using the macro SET_ALIGN(16) as prefix instead of the direct struct alignas(16) leads to a "missing semicolon" error.

Steps To Reproduce/Bad Parse Tree
translation_unit [0, 0] - [1, 0]
  expression_statement [0, 0] - [0, 13]
    call_expression [0, 0] - [0, 13]
      function: identifier [0, 0] - [0, 9]
      arguments: argument_list [0, 9] - [0, 13]
        number_literal [0, 10] - [0, 12]
    MISSING ; [0, 13] - [0, 13]
  declaration [0, 14] - [0, 27]
    type: type_identifier [0, 14] - [0, 17]
    declarator: init_declarator [0, 18] - [0, 26]
      declarator: identifier [0, 18] - [0, 21]
      value: initializer_list [0, 24] - [0, 26]
Expected Behavior/Parse Tree

This might be difficult to handle, as the macro could be a regular function call that just happened to have no newline after it and is indeed missing a semicolon. A heuristic based on the missing line-break would work but be rather hacky. The parser recovers from this though.

Repro
SET_ALIGN(16) Foo bar = {};

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 reproducing SET_ALIGN(16) Foo bar = {}; in the tree-sitter-cpp Playground and inspect the reported parse tree. Compare it with the direct struct alignas(16) form and the parser documentation linked in the issue. The issue does not define a precise expected parse tree or a settled approach, so completion would require deciding how to distinguish a macro prefix from a function call before adding coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.