bug-indent
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Stmt nesting error on if(condition)/*comment*/{{}} with -br option


From: Petr Pisar
Subject: Stmt nesting error on if(condition)/*comment*/{{}} with -br option
Date: Wed, 21 Oct 2020 18:26:50 +0200

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

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]