mozilla / mozilla/cbindgen

Extra semicolon with `define`

Open
#1,058 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
3k
Forks
386
Avg merge
1h 43m
Merged PRs (30d)
1

Description

Given this code:

#[repr(C)]
struct Foobar {
    a: u32,
    #[cfg(feature="xyz")]
    b: u32,
    c: u32,
}

#[no_mangle]
pub extern "C" fn xx(_f: &Foobar) {}

and this configuration:

[defines]
"feature = xyz" = "XYZ"

cbindgen generates the following for the struct

struct Foobar {
  uint32_t a;
#if defined(XYZ)
  uint32_t b
#endif
  ;
  uint32_t c;
};

As you can see, the ; is not in the #if, for some reason.

When compiling the code with with -Wextra-semi, gcc generates the following warning:

<source>:8:3: warning: extra ';' inside a struct [-Wextra-semi]
    8 |   ;
      |   ^
      |   -

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

Reproduce the issue with the Rust Foobar snippet and the [defines] configuration shown in the report, then inspect the generated C++ around the cfg-controlled field. The generated semicolon should remain inside the conditional block so GCC does not report an extra semicolon with -Wextra-semi.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
tooling
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.