pycparser
pycparser copied to clipboard
Generating compound expression returning compound literal incorrectly omits final semicolon
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;
}
;
}
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.