Stmt nesting error on if(condition)/*comment*/{{}} with -br option
Petr Pisar <[email protected]> Wed, 21 Oct 2020 18:26:50 +0200
| Newsgroups | gmane.comp.gnu.indent.bugs |
|---|---|
| Message-ID | <[email protected]> |
--r5Pyd7+fXNt84Ff3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Hello,
I got a bug report <https://bugzilla.redhat.com/show_bug.cgi?id=1888840> that
this code:
if (condition) /*comment*/
{
{
int x = 0;
}
}
breaks indent -br. The processing terminates with the following error message:
indent: /tmp/test.c:6: Error:Stmt nesting error.
It seems that parser_state_tos->tos goes out of synchronization when
search_brace() saves the comment and subseqent left braces until the variable
declaration into save_com buffer and reparses them. As a result the left
braces do not increase parser_state_tos->tos, and then when parsing the
closing right-braces, the parser reports the nesting error.
This happens only if -br switch is used. -bl works fine. Also there must be
the comment and at least two nesting brace blocks.
Unfortunetaly I'm unable to fix. It seems that handling the comment
(i.e. moving the first brace between the condition and the comment):
if (condition) { /*comment*/
{
int x = 0;
}
}
cheats the parser, but not flawlesly. And the handling (settings.btype_2) is
spread onto multiple places of indent making the fix difficult.
-- Petr
--r5Pyd7+fXNt84Ff3
Content-Type: application/pgp-signature; name="signature.asc"
-----BEGIN PGP SIGNATURE-----
iQIzBAABCAAdFiEE4/QvzhVoMKgDWObpT9GuwzZa978FAl+QYUYACgkQT9GuwzZa
97+MZBAAu9tWmnGZsP/c6l7+zOy/m//58a7vi8W2r0pAicHqCvSJHrhebKHZyHyq
slMl5FXLRqRsMYrtZyeir4FLqD0gt/x6YTnTMVoiDzPyO33sllZC04z9tOp2iSdB
UxEVbCcYG5KmD1v8CBtFrC2Hm0yqC0SeNq0uFiE6wMLvzHs965LKyLmU+iwgt5nl
ZPlxZ+YpITEx2c4Hr/QeiXFrJNIHXJqnTTtPrSoczUl7vYEMeEbZAi7pADLvooWA
9M/3zQnfRT2q8LShf5gx/LTxXg5YNu7ETTsiayg720gx/MMQ1DncJjJAU2C1dxOK
9YkMqnoacPZCx/YLX65UR+iF33G1c5gqyZhtnWxlpfAVxSP7zwKrhEQy9lOqxS3r
TumInEcxyHly6v1AbgPwq+xb+BspvwVbFK7szxCDreKp2T5sh9t9nlAmquNr2gNu
XlYIRePqYhkKouEJqioAUzTEiOC7JvIXmocz5U3q2lakCIBgudg9G2OQsQ/Kmsb5
Z3W/rTigUE5y3ReJfoO1exXC8ZyvUj/2Guba565tPaIAAbYzF8n+R8/kpG+rQYQo
R8VRhsAYCGxsl/cZE9W4qJPIRcJbZPAu48u+wVXypoxgKtaVszYbiopjGkCnGiUf
iIGWY0965dJ/heyceeA77tVcRrqPtXWXgRt/r45Bcv6nyPLhQWw=
=qfpp
-----END PGP SIGNATURE-----
--r5Pyd7+fXNt84Ff3--