forked from OSchip/llvm-project
clang-format: Format enum struct/class like enum.
Patch by Joe Hermaszewski. Thank you! llvm-svn: 188794
This commit is contained in:
parent
b55acad91c
commit
2b41a82e61
|
@ -918,6 +918,10 @@ void UnwrappedLineParser::parseAccessSpecifier() {
|
|||
|
||||
void UnwrappedLineParser::parseEnum() {
|
||||
nextToken();
|
||||
// Eat up enum class ...
|
||||
if (FormatTok->Tok.is(tok::kw_class) ||
|
||||
FormatTok->Tok.is(tok::kw_struct))
|
||||
nextToken();
|
||||
if (FormatTok->Tok.is(tok::identifier) ||
|
||||
FormatTok->Tok.is(tok::kw___attribute) ||
|
||||
FormatTok->Tok.is(tok::kw___declspec)) {
|
||||
|
|
|
@ -1518,6 +1518,40 @@ TEST_F(FormatTest, FormatsEnum) {
|
|||
verifyFormat("enum X f() {\n a();\n return 42;\n}");
|
||||
}
|
||||
|
||||
TEST_F(FormatTest, FormatsEnumStruct) {
|
||||
verifyFormat("enum struct {\n"
|
||||
" Zero,\n"
|
||||
" One = 1,\n"
|
||||
" Two = One + 1,\n"
|
||||
" Three = (One + Two),\n"
|
||||
" Four = (Zero && (One ^ Two)) | (One << Two),\n"
|
||||
" Five = (One, Two, Three, Four, 5)\n"
|
||||
"};");
|
||||
verifyFormat("enum struct Enum {};");
|
||||
verifyFormat("enum struct {};");
|
||||
verifyFormat("enum struct X E {\n} d;");
|
||||
verifyFormat("enum struct __attribute__((...)) E {\n} d;");
|
||||
verifyFormat("enum struct __declspec__((...)) E {\n} d;");
|
||||
verifyFormat("enum struct X f() {\n a();\n return 42;\n}");
|
||||
}
|
||||
|
||||
TEST_F(FormatTest, FormatsEnumClass) {
|
||||
verifyFormat("enum class {\n"
|
||||
" Zero,\n"
|
||||
" One = 1,\n"
|
||||
" Two = One + 1,\n"
|
||||
" Three = (One + Two),\n"
|
||||
" Four = (Zero && (One ^ Two)) | (One << Two),\n"
|
||||
" Five = (One, Two, Three, Four, 5)\n"
|
||||
"};");
|
||||
verifyFormat("enum class Enum {};");
|
||||
verifyFormat("enum class {};");
|
||||
verifyFormat("enum class X E {\n} d;");
|
||||
verifyFormat("enum class __attribute__((...)) E {\n} d;");
|
||||
verifyFormat("enum class __declspec__((...)) E {\n} d;");
|
||||
verifyFormat("enum class X f() {\n a();\n return 42;\n}");
|
||||
}
|
||||
|
||||
TEST_F(FormatTest, FormatsBitfields) {
|
||||
verifyFormat("struct Bitfields {\n"
|
||||
" unsigned sClass : 8;\n"
|
||||
|
|
Loading…
Reference in New Issue