[PATCH 6/9] indent.c: Don't force nl between rbrace and comma
Tim Hentenaar <[email protected]> Wed, 17 Jun 2015 20:56:02 +0200
| Newsgroups | gmane.comp.gnu.indent.bugs |
|---|---|
| Message-ID | <[email protected]> |
In a block initializer, don't force a newline between the rbrace and the comma. This fixes the issue reported by Clark Wang. --- ChangeLog | 2 ++ regression/TEST | 3 ++- regression/input/no-forced-nl-in-block-init.c | 14 ++++++++++++++ regression/standard/no-forced-nl-in-block-init.c | 16 ++++++++++++++++ src/indent.c | 6 ++++++ 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 regression/input/no-forced-nl-in-block-init.c create mode 100644 regression/standard/no-forced-nl-in-block-init.c diff --git a/ChangeLog b/ChangeLog index 6191914..d7786b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,8 @@ * comments.c: Prevent heap corruption via writing past the end of combuf by adding a size check in places where we're writing to combuf by looping and incrememnting e_com. + * indent.c: Don't force a newline after an rbrace and before a + comma in a block initializer. 2015-06-16 Tim Hentenaar <[email protected]> * Use want_blank instead of copying a space to e_code to avoid diff --git a/regression/TEST b/regression/TEST index 0962de9..a5a7ec8 100755 --- a/regression/TEST +++ b/regression/TEST @@ -36,7 +36,8 @@ EXAMPLES="do.c else.c for.c func-def.c lshift.c ncs.c \ BUGS="case-label.c one-line-1.c one-line-2.c one-line-3.c \ one-line-4.c struct-decl.c sizeof-in-while.c line-break-comment.c \ macro.c enum.c elif.c nested.c wrapped-string.c minus_predecrement.c \ - bug-gnu-33364.c float-constant-suffix.c block-comments.c" + bug-gnu-33364.c float-constant-suffix.c block-comments.c \ + no-forced-nl-in-block-init.c" INDENTSRC="args.c backup.h backup.c dirent_def.h globs.c indent.h \ indent.c indent_globs.h io.c lexi.c memcpy.c parse.c pr_comment.c \ diff --git a/regression/input/no-forced-nl-in-block-init.c b/regression/input/no-forced-nl-in-block-init.c new file mode 100644 index 0000000..4e8571f --- /dev/null +++ b/regression/input/no-forced-nl-in-block-init.c @@ -0,0 +1,14 @@ +void foo() +{ + struct_a arr[] = { + { &a, sizeof (a) }, + { &b, sizeof (b) }, + { &c, sizeof (c) }, + { &d, sizeof (d) } + }; + + struct { + int a; + int b; + } v = { 0 }; +} diff --git a/regression/standard/no-forced-nl-in-block-init.c b/regression/standard/no-forced-nl-in-block-init.c new file mode 100644 index 0000000..96858b7 --- /dev/null +++ b/regression/standard/no-forced-nl-in-block-init.c @@ -0,0 +1,16 @@ +void +foo () +{ + struct_a arr[] = { + {&a, sizeof (a)}, + {&b, sizeof (b)}, + {&c, sizeof (c)}, + {&d, sizeof (d)} + }; + + struct + { + int a; + int b; + } v = { 0 }; +} diff --git a/src/indent.c b/src/indent.c index 64c9cbc..091a3ed 100644 --- a/src/indent.c +++ b/src/indent.c @@ -538,6 +538,12 @@ static exit_values_ty indent_main_loop( parser_state_tos->last_token == sp_else)) force_nl = false; + /* Don't force a newline after '}' in a block initializer */ + if (parser_state_tos->block_init && + parser_state_tos->last_token == rbrace && + *token == ',') + force_nl = false; + if (!search_brace(&type_code, &force_nl, &flushed_nl, &last_else, &is_procname_definition, pbreak_line)) { -- 2.3.6