[clang] 072ae7c - [clang-format] Always break line after enum opening brace
via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 13 07:04:14 PDT 2020
Author: mydeveloperday
Date: 2020-04-13T15:03:36+01:00
New Revision: 072ae7c1e64f8dd1b5e9db17838c93b150f8b487
URL: https://github.com/llvm/llvm-project/commit/072ae7c1e64f8dd1b5e9db17838c93b150f8b487
DIFF: https://github.com/llvm/llvm-project/commit/072ae7c1e64f8dd1b5e9db17838c93b150f8b487.diff
LOG: [clang-format] Always break line after enum opening brace
Summary:
clang-format currently puts the first enumerator on the same line as the
enum keyword and opening brace if it fits (for example, for anonymous
enums if IndentWidth is 8):
$ echo "enum { RED, GREEN, BLUE };" | clang-format -style="{BasedOnStyle: llvm, ColumnLimit: 15, IndentWidth: 8}"
enum { RED,
GREEN,
BLUE };
This doesn't seem to be intentional, as I can't find any style guide that
suggests wrapping enums this way. Always force the enumerator to be on a new
line, which gets us the desired result:
$ echo "enum { RED, GREEN, BLUE };" | ./bin/clang-format -style="{BasedOnStyle: llvm, ColumnLimit: 15, IndentWidth: 8}"
enum {
RED,
GREEN,
BLUE
};
Test Plan:
New test added. Confirmed test failed without change and passed with change by
running:
$ ninja FormatTests && ./tools/clang/unittests/Format/FormatTests
Reviewed By: MyDeveloperDay
Patch By: osandov
Tags: #clang-format, #clang
Differential Revision: https://reviews.llvm.org/D77682
Added:
Modified:
clang/lib/Format/ContinuationIndenter.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 03e79a22954e..2dda5d89a3ac 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -423,7 +423,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
State.Stack.back().BreakBeforeParameter && Current.CanBreakBefore)
return true;
- if (State.Column <= NewLineColumn)
+ if (!State.Line->First->is(tok::kw_enum) && State.Column <= NewLineColumn)
return false;
if (Style.AlwaysBreakBeforeMultilineStrings &&
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index fe16eeaba53c..ece7c61a999c 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -1929,6 +1929,24 @@ TEST_F(FormatTest, FormatsEnum) {
" TWO\n"
"};\n"
"int i;");
+
+ FormatStyle EightIndent = getLLVMStyle();
+ EightIndent.IndentWidth = 8;
+ verifyFormat("enum {\n"
+ " VOID,\n"
+ " CHAR,\n"
+ " SHORT,\n"
+ " INT,\n"
+ " LONG,\n"
+ " SIGNED,\n"
+ " UNSIGNED,\n"
+ " BOOL,\n"
+ " FLOAT,\n"
+ " DOUBLE,\n"
+ " COMPLEX\n"
+ "};",
+ EightIndent);
+
// Not enums.
verifyFormat("enum X f() {\n"
" a();\n"
More information about the cfe-commits
mailing list