Rust-GCC / Rust-GCC/gccrs

Macros are not correctly parsed

Open
#2,126 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
2.9k
Forks
231
Avg merge
19h 55m
Merged PRs (30d)
67

Description

I tried this code:

macro_rules! itemizer {
    () => {
        struct S;

        impl S {
            fn new() -> S { S }
        }
    }
}

I expected to see this happen:

Compiles correctly, but the AST should consider it as "not semicoloned".

Instead, this happened:

It compiles correctly but is considered to have a semicolon. Therefore the tokenstream dumper cannot rely on "is_semicoloned" to guess wether a semicolon shall output.

A simple fix would be rust-parse-impl.h line 1801

      return AST::MacroInvocation::Regular (std::move (invoc_data),
					    std::move (outer_attrs),
-					    macro_locus, true);
+					    macro_locus, false);

But it breaks the testsuite since the semicolon status is relied on with a different behavior during the macro expansion.

Meta
  • e7ea5fb64026c72f4f93e1ecd92ce7e5d2941b54

Contributor guide

Open the contributing guide

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 at rust-parse-impl.h line 1801 and inspect AST::MacroInvocation::Regular, then run the affected testsuite cases around macro expansion and semicolon handling. Trace how the tokenstream dumper uses is_semicoloned. Done means the AST records the macro invocation's semicolon status correctly without breaking the existing testsuite behavior during expansion.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.