================
@@ -4266,6 +4266,140 @@ TEST_F(FormatTest, FormatsTypedefEnum) {
                Style);
 }
 
+TEST_F(FormatTest, FormatsVaOptWithTrailingComma) {
+  verifyFormat("#define DEFINE_DESCRIPTOR(Name, ...) \\\n"
+               "  enum ParameterIndices {            \\\n"
+               "    kJSTarget = -1,                  \\\n"
+               "    __VA_OPT__(__VA_ARGS__, )        \\\n"
+               "    kNewTarget,                      \\\n"
+               "    kActualArgumentsCount,           \\\n"
+               "    kContext,                        \\\n"
+               "    kParameterCount,                 \\\n"
+               "  };",
+               getChromiumStyle(FormatStyle::LK_Cpp));
+
+  FormatStyle Style = getLLVMStyle();
+  Style.AlignEscapedNewlines = FormatStyle::ENAS_Left;
+
+  verifyFormat("#define M(...) enum E { __VA_OPT__(__VA_ARGS__, ) kOnly };",
+               Style);
+  FormatStyle NoShortEnums = Style;
+  NoShortEnums.AllowShortEnumsOnASingleLine = false;
+  verifyFormat("#define M(...)                \\\n"
+               "  enum E {                    \\\n"
+               "    __VA_OPT__(__VA_ARGS__, ) \\\n"
+               "    kOnly                     \\\n"
+               "  };",
+               NoShortEnums);
+
+  FormatStyle InsertComma = NoShortEnums;
+  InsertComma.EnumTrailingComma = FormatStyle::ETC_Insert;
----------------
backes wrote:

This case intentionally verifies that `ETC_Insert` does *not* insert a spurious 
`,` after `__VA_OPT__(__VA_ARGS__, )` (which would turn a non-empty expansion 
into `a, ,`). The 2-argument `verifyFormat` catches a regression directly 
because `format()` would otherwise insert `,` after `)`. I also updated 
`InsertComma` to inherit `AllowShortEnumsOnASingleLine = true` so this case 
covers `mustBreakBefore` as well.

https://github.com/llvm/llvm-project/pull/240902
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to