From d50b47daebf0a3153a610ac64e5fb19f79fc3be9 Mon Sep 17 00:00:00 2001 From: Guy Maurel Date: Wed, 9 Sep 2020 18:15:39 +0200 Subject: [PATCH 1/2] If empty, do not introduce a comma Fixes #2902 --- src/enum_cleanup.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/enum_cleanup.cpp b/src/enum_cleanup.cpp index 8740277601..f3d43eb56e 100644 --- a/src/enum_cleanup.cpp +++ b/src/enum_cleanup.cpp @@ -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); + } } } } From 8edb7262e855c4271e9e5fc26af93861103e14fa Mon Sep 17 00:00:00 2001 From: Guy Maurel Date: Thu, 10 Sep 2020 18:35:29 +0200 Subject: [PATCH 2/2] provide test data --- tests/config/Issue_2902.cfg | 1 + tests/cpp.test | 1 + tests/expected/cpp/30303-Issue_2902.cpp | 1 + tests/input/cpp/Issue_2902.cpp | 1 + 4 files changed, 4 insertions(+) create mode 100644 tests/config/Issue_2902.cfg create mode 100644 tests/expected/cpp/30303-Issue_2902.cpp create mode 100644 tests/input/cpp/Issue_2902.cpp diff --git a/tests/config/Issue_2902.cfg b/tests/config/Issue_2902.cfg new file mode 100644 index 0000000000..5806b37123 --- /dev/null +++ b/tests/config/Issue_2902.cfg @@ -0,0 +1 @@ +mod_enum_last_comma = add diff --git a/tests/cpp.test b/tests/cpp.test index 1be53969da..3554390ffd 100644 --- a/tests/cpp.test +++ b/tests/cpp.test @@ -222,6 +222,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 diff --git a/tests/expected/cpp/30303-Issue_2902.cpp b/tests/expected/cpp/30303-Issue_2902.cpp new file mode 100644 index 0000000000..ae10d5a90c --- /dev/null +++ b/tests/expected/cpp/30303-Issue_2902.cpp @@ -0,0 +1 @@ +enum empty {}; diff --git a/tests/input/cpp/Issue_2902.cpp b/tests/input/cpp/Issue_2902.cpp new file mode 100644 index 0000000000..ae10d5a90c --- /dev/null +++ b/tests/input/cpp/Issue_2902.cpp @@ -0,0 +1 @@ +enum empty {};