From 2b41a82e61977479bd0cb98706030e652c76e3a6 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 20 Aug 2013 12:42:50 +0000 Subject: [PATCH] clang-format: Format enum struct/class like enum. Patch by Joe Hermaszewski. Thank you! llvm-svn: 188794 --- clang/lib/Format/UnwrappedLineParser.cpp | 4 +++ clang/unittests/Format/FormatTest.cpp | 34 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 56fe81f3f2be..d77f931b718d 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -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)) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 5ebae5f6b27a..434278121778 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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"