pycparser icon indicating copy to clipboard operation
pycparser copied to clipboard

Generating compound expression returning compound literal incorrectly omits final semicolon

Open bbb23exposed opened this issue 1 year ago • 1 comments

ast = pycparserext.ext_c_parser.GnuCParser().parse("""
struct a {
    int m;
};

struct a test() {
    int x = 1;
    return ({
        (struct a){x};
    });
}""")

print(pycparserext.ext_c_generator.GnuCGenerator().visit(ast))

output:

{
  int m;
};
struct a test()
{
  int x = 1;
  return   {
    (struct a){x}
  }
;
}

Compare with:

ast = pycparserext.ext_c_parser.GnuCParser().parse("""
struct a {
    int m;
};

struct a test() {
    int x = 1;
    return ({
        x;
    });
}""")

output:

struct a
{
  int m;
};
struct a test()
{
  int x = 1;
  return   {
    x;
  }
;
}

bbb23exposed avatar Jun 14 '25 00:06 bbb23exposed

I can take this. I’ll add a regression in tests/test_c_generator.py that fails on current main, keep the generator change limited to compound literals used as statements, and run python -m unittest discover as requested on the previous attempt.

Rayan-and-beyond avatar Sep 15 '26 04:09 Rayan-and-beyond