Skip to content

Commit

Permalink
Merge pull request #2905 from guy-maurel/NoCommaEmptyEnum
Browse files Browse the repository at this point in the history
If empty, do not introduce a comma
  • Loading branch information
gmaurel committed Sep 11, 2020
2 parents a3ff639 + 8edb726 commit c0d152a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/enum_cleanup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,27 @@ void enum_cleanup(void)
}
else
{
log_rule_B("mod_enum_last_comma");

if ( options::mod_enum_last_comma() == IARF_ADD
|| options::mod_enum_last_comma() == IARF_FORCE)
if (chunk_is_token(prev, CT_BRACE_OPEN)) // Issue #2902
{
// create a comma
chunk_t comma;
set_chunk_type(&comma, CT_COMMA);
comma.orig_line = prev->orig_line;
comma.orig_col = prev->orig_col + 1;
comma.nl_count = 0;
comma.flags = PCF_NONE;
comma.str = ",";
chunk_add_after(&comma, prev);
// nothing betwen CT_BRACE_OPEN and CT_BRACE_CLOSE
}
else
{
log_rule_B("mod_enum_last_comma");

if ( options::mod_enum_last_comma() == IARF_ADD
|| options::mod_enum_last_comma() == IARF_FORCE)
{
// create a comma
chunk_t comma;
set_chunk_type(&comma, CT_COMMA);
comma.orig_line = prev->orig_line;
comma.orig_col = prev->orig_col + 1;
comma.nl_count = 0;
comma.flags = PCF_NONE;
comma.str = ",";
chunk_add_after(&comma, prev);
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/config/Issue_2902.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod_enum_last_comma = add
1 change: 1 addition & 0 deletions tests/cpp.test
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@
30300 ben_020.cfg cpp/enum_shr.cpp
30301 al.cfg cpp/enum_class.h
30302 bug_1315.cfg cpp/bug_1315.cpp
30303 Issue_2902.cfg cpp/Issue_2902.cpp

# TODO: Make a tests for a braced_init_list. See also 34153-34166.
30310 sp_word_brace_force.cfg cpp/braced_init_list.cpp
Expand Down
1 change: 1 addition & 0 deletions tests/expected/cpp/30303-Issue_2902.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enum empty {};
1 change: 1 addition & 0 deletions tests/input/cpp/Issue_2902.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enum empty {};

0 comments on commit c0d152a

Please sign in to comment.