[clang] [clang-format] Add SpaceBeforeEnumUnderlyingTypeColon for enum underlying types (PR #189011)
Tharun V K via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 1 03:26:42 PDT 2026
https://github.com/tharunvk updated https://github.com/llvm/llvm-project/pull/189011
>From 6aefab3858a4d4b6eb2cba5a5c0d9b921d5c7293 Mon Sep 17 00:00:00 2001
From: Tharun V K <Tharun.V.K at ibm.com>
Date: Fri, 27 Mar 2026 19:47:35 +0530
Subject: [PATCH 1/7] [clang-format] Apply SpaceBeforeInheritanceColon to enum
underlying types
---
clang/docs/ClangFormatStyleOptions.rst | 4 +++-
clang/include/clang/Format/Format.h | 4 +++-
clang/lib/Format/TokenAnnotator.cpp | 4 ++--
clang/unittests/Format/FormatTest.cpp | 18 ++++++++++++++++++
4 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index f637b81bb75bc..69def14d7e371 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6834,12 +6834,14 @@ the configuration (without a prefix: ``Auto``).
.. _SpaceBeforeInheritanceColon:
**SpaceBeforeInheritanceColon** (``Boolean``) :versionbadge:`clang-format 7` :ref:`¶ <SpaceBeforeInheritanceColon>`
- If ``false``, spaces will be removed before inheritance colon.
+ If ``false``, spaces will be removed before inheritance colon
+ and enum underlying type colon.
.. code-block:: c++
true: false:
class Foo : Bar {} vs. class Foo: Bar {}
+ enum E : int {} enum E: int {}
.. _SpaceBeforeJsonColon:
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index 8c90cc2e98121..9247814a3edf2 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5121,10 +5121,12 @@ struct FormatStyle {
/// \version 7
bool SpaceBeforeCtorInitializerColon;
- /// If ``false``, spaces will be removed before inheritance colon.
+ /// If ``false``, spaces will be removed before inheritance colon
+ /// and enum underlying type colon.
/// \code
/// true: false:
/// class Foo : Bar {} vs. class Foo: Bar {}
+ /// enum E : int {} enum E: int {}
/// \endcode
/// \version 7
bool SpaceBeforeInheritanceColon;
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index d2cdc28a7da7b..50f290817eea2 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1444,9 +1444,9 @@ class AnnotatingParser {
Scopes.back() == ST_Class)) {
Tok->setType(TT_BitFieldColon);
} else if (Contexts.size() == 1 &&
- Line.getFirstNonComment()->isNoneOf(tok::kw_enum, tok::kw_case,
+ Line.getFirstNonComment()->isNoneOf(tok::kw_case,
tok::kw_default) &&
- !Line.startsWith(tok::kw_typedef, tok::kw_enum)) {
+ !Line.startsWith(tok::kw_typedef)) {
if (Prev->isOneOf(tok::r_paren, tok::kw_noexcept) ||
Prev->ClosesRequiresClause) {
Tok->setType(TT_CtorInitializerColon);
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 2701a7fca7346..8f2c8efd012c6 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -18632,6 +18632,24 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeColon) {
InvertedSpaceStyle);
}
+TEST_F(FormatTest, EnumUnderlyingTypeUsesInheritanceColonSpacing) {
+ FormatStyle Style = getLLVMStyle();
+
+ Style.SpaceBeforeInheritanceColon = true;
+ verifyFormat("enum A : int {};", Style);
+ verifyFormat("enum class B : int {};", Style);
+ verifyFormat("enum : int { E1 };", Style);
+ verifyFormat("typedef enum : int { E2 } E3;", Style);
+ verifyFormat("typedef enum A : int { E4 } B;", Style);
+
+ Style.SpaceBeforeInheritanceColon = false;
+ verifyFormat("enum A: int {};", Style);
+ verifyFormat("enum class B: int {};", Style);
+ verifyFormat("enum: int { E1 };", Style);
+ verifyFormat("typedef enum: int { E2 } E3;", Style);
+ verifyFormat("typedef enum A: int { E4 } B;", Style);
+}
+
TEST_F(FormatTest, ConfigurableSpaceAroundPointerQualifiers) {
FormatStyle Style = getLLVMStyle();
>From 7f1929adaf999ce6810260b63d637d51a37e8a5c Mon Sep 17 00:00:00 2001
From: Tharun V K <tharunms98 at gmail.com>
Date: Sun, 29 Mar 2026 07:35:54 +0530
Subject: [PATCH 2/7] [clang-format] Handle typedef enum underlying type colon
---
clang/lib/Format/TokenAnnotator.cpp | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 50f290817eea2..83b6c1954b44b 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1443,10 +1443,8 @@ class AnnotatingParser {
(Prev->is(TT_StartOfName) && !Scopes.empty() &&
Scopes.back() == ST_Class)) {
Tok->setType(TT_BitFieldColon);
- } else if (Contexts.size() == 1 &&
- Line.getFirstNonComment()->isNoneOf(tok::kw_case,
- tok::kw_default) &&
- !Line.startsWith(tok::kw_typedef)) {
+ } else if (Contexts.size() == 1 && Line.getFirstNonComment()->isNoneOf(
+ tok::kw_case, tok::kw_default)) {
if (Prev->isOneOf(tok::r_paren, tok::kw_noexcept) ||
Prev->ClosesRequiresClause) {
Tok->setType(TT_CtorInitializerColon);
>From adf1154f1a7b67e0150aed03aad29483d6c6d78b Mon Sep 17 00:00:00 2001
From: Tharun V K <tharunms98 at gmail.com>
Date: Tue, 31 Mar 2026 00:51:41 +0530
Subject: [PATCH 3/7] Add new type EnumUnderlyingTypeColon for enum underlying
types
---
clang/lib/Format/FormatToken.h | 1 +
clang/lib/Format/TokenAnnotator.cpp | 11 ++++++++++-
clang/lib/Format/UnwrappedLineParser.cpp | 2 ++
3 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index ba9a95440f0c2..e75d1affaa862 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -78,6 +78,7 @@ namespace format {
TYPE(ElseRBrace) \
TYPE(EnumLBrace) \
TYPE(EnumRBrace) \
+ TYPE(EnumUnderlyingTypeColon) \
TYPE(FatArrow) \
TYPE(ForEachMacro) \
TYPE(FunctionAnnotationRParen) \
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 83b6c1954b44b..24b0a45ec1228 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1456,7 +1456,12 @@ class AnnotatingParser {
if (PrevPrev && PrevPrev->isOneOf(tok::r_paren, tok::kw_noexcept))
Tok->setType(TT_CtorInitializerColon);
} else {
- Tok->setType(TT_InheritanceColon);
+ if (Line.startsWith(tok::kw_enum) ||
+ Line.startsWith(tok::kw_typedef, tok::kw_enum)) {
+ Tok->setType(TT_EnumUnderlyingTypeColon);
+ } else {
+ Tok->setType(TT_InheritanceColon);
+ }
if (Prev->isAccessSpecifierKeyword())
Line.Type = LT_AccessModifier;
}
@@ -5549,6 +5554,10 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
return Style.SpaceBeforeCtorInitializerColon;
if (Right.is(TT_InheritanceColon) && !Style.SpaceBeforeInheritanceColon)
return false;
+ if (Right.is(TT_EnumUnderlyingTypeColon) &&
+ !Style.SpaceBeforeInheritanceColon) {
+ return false;
+ }
if (Right.is(TT_RangeBasedForLoopColon) &&
!Style.SpaceBeforeRangeBasedForLoopColon) {
return false;
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index a3e8a3e270e73..aaec7951a12df 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3838,6 +3838,8 @@ bool UnwrappedLineParser::parseEnum() {
FormatTok->isOneOf(tok::colon, tok::coloncolon, tok::less,
tok::greater, tok::comma, tok::question,
tok::l_square)) {
+ if (FormatTok->is(tok::colon))
+ FormatTok->setType(TT_EnumUnderlyingTypeColon);
if (Style.isVerilog()) {
FormatTok->setFinalizedType(TT_VerilogDimensionedTypeName);
nextToken();
>From fe2281c53faa499a0b4e8580a61814da71d33956 Mon Sep 17 00:00:00 2001
From: Tharun V K <tharunms98 at gmail.com>
Date: Tue, 31 Mar 2026 02:12:58 +0530
Subject: [PATCH 4/7] Moved tests to TokenAnnotator
---
clang/lib/Format/TokenAnnotator.cpp | 13 +++++------
clang/lib/Format/UnwrappedLineParser.cpp | 2 +-
clang/unittests/Format/FormatTest.cpp | 8 -------
clang/unittests/Format/TokenAnnotatorTest.cpp | 22 ++++++++++++++++---
4 files changed, 25 insertions(+), 20 deletions(-)
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 24b0a45ec1228..0c185cc08f728 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1443,8 +1443,10 @@ class AnnotatingParser {
(Prev->is(TT_StartOfName) && !Scopes.empty() &&
Scopes.back() == ST_Class)) {
Tok->setType(TT_BitFieldColon);
- } else if (Contexts.size() == 1 && Line.getFirstNonComment()->isNoneOf(
- tok::kw_case, tok::kw_default)) {
+ } else if (Contexts.size() == 1 &&
+ Line.getFirstNonComment()->isNoneOf(tok::kw_enum, tok::kw_case,
+ tok::kw_default) &&
+ !Line.startsWith(tok::kw_typedef, tok::kw_enum)) {
if (Prev->isOneOf(tok::r_paren, tok::kw_noexcept) ||
Prev->ClosesRequiresClause) {
Tok->setType(TT_CtorInitializerColon);
@@ -1456,12 +1458,7 @@ class AnnotatingParser {
if (PrevPrev && PrevPrev->isOneOf(tok::r_paren, tok::kw_noexcept))
Tok->setType(TT_CtorInitializerColon);
} else {
- if (Line.startsWith(tok::kw_enum) ||
- Line.startsWith(tok::kw_typedef, tok::kw_enum)) {
- Tok->setType(TT_EnumUnderlyingTypeColon);
- } else {
- Tok->setType(TT_InheritanceColon);
- }
+ Tok->setType(TT_InheritanceColon);
if (Prev->isAccessSpecifierKeyword())
Line.Type = LT_AccessModifier;
}
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index aaec7951a12df..e9a5b3fb4d21c 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3839,7 +3839,7 @@ bool UnwrappedLineParser::parseEnum() {
tok::greater, tok::comma, tok::question,
tok::l_square)) {
if (FormatTok->is(tok::colon))
- FormatTok->setType(TT_EnumUnderlyingTypeColon);
+ FormatTok->setFinalizedType(TT_EnumUnderlyingTypeColon);
if (Style.isVerilog()) {
FormatTok->setFinalizedType(TT_VerilogDimensionedTypeName);
nextToken();
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 8f2c8efd012c6..3bf20879d1cd2 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -18637,17 +18637,9 @@ TEST_F(FormatTest, EnumUnderlyingTypeUsesInheritanceColonSpacing) {
Style.SpaceBeforeInheritanceColon = true;
verifyFormat("enum A : int {};", Style);
- verifyFormat("enum class B : int {};", Style);
- verifyFormat("enum : int { E1 };", Style);
- verifyFormat("typedef enum : int { E2 } E3;", Style);
- verifyFormat("typedef enum A : int { E4 } B;", Style);
Style.SpaceBeforeInheritanceColon = false;
verifyFormat("enum A: int {};", Style);
- verifyFormat("enum class B: int {};", Style);
- verifyFormat("enum: int { E1 };", Style);
- verifyFormat("typedef enum: int { E2 } E3;", Style);
- verifyFormat("typedef enum A: int { E4 } B;", Style);
}
TEST_F(FormatTest, ConfigurableSpaceAroundPointerQualifiers) {
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index efb361387bb1e..a0a2be97f8d10 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -4339,10 +4339,26 @@ TEST_F(TokenAnnotatorTest, UserDefinedLiteral) {
EXPECT_EQ(Tokens[3]->TokenText, "2_$");
}
-TEST_F(TokenAnnotatorTest, EnumColonInTypedef) {
- auto Tokens = annotate("typedef enum : int {} foo;");
+TEST_F(TokenAnnotatorTest, EnumColon) {
+ auto Tokens = annotate("enum A : int {};");
+ ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+ EXPECT_TOKEN(Tokens[2], tok::colon, TT_EnumUnderlyingTypeColon);
+
+ Tokens = annotate("enum class B : int {};");
+ ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+ EXPECT_TOKEN(Tokens[3], tok::colon, TT_EnumUnderlyingTypeColon);
+
+ Tokens = annotate("enum : int { E1 };");
+ ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+ EXPECT_TOKEN(Tokens[1], tok::colon, TT_EnumUnderlyingTypeColon);
+
+ Tokens = annotate("typedef enum : int {} foo;");
ASSERT_EQ(Tokens.size(), 9u) << Tokens;
- EXPECT_TOKEN(Tokens[2], tok::colon, TT_Unknown); // Not TT_InheritanceColon.
+ EXPECT_TOKEN(Tokens[2], tok::colon, TT_EnumUnderlyingTypeColon);
+
+ Tokens = annotate("typedef enum A : int {} foo;");
+ ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+ EXPECT_TOKEN(Tokens[3], tok::colon, TT_EnumUnderlyingTypeColon);
}
TEST_F(TokenAnnotatorTest, BitFieldColon) {
>From 956b210726d6c4e5361304bb8df4d6a763c6d7ff Mon Sep 17 00:00:00 2001
From: Tharun V K <tharunms98 at gmail.com>
Date: Tue, 31 Mar 2026 08:13:40 +0530
Subject: [PATCH 5/7] Consider EOF token also for Token size. Fixes CI test
fail
---
clang/unittests/Format/TokenAnnotatorTest.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index a0a2be97f8d10..2ba94636d933b 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -4341,11 +4341,11 @@ TEST_F(TokenAnnotatorTest, UserDefinedLiteral) {
TEST_F(TokenAnnotatorTest, EnumColon) {
auto Tokens = annotate("enum A : int {};");
- ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+ ASSERT_EQ(Tokens.size(), 8u) << Tokens;
EXPECT_TOKEN(Tokens[2], tok::colon, TT_EnumUnderlyingTypeColon);
Tokens = annotate("enum class B : int {};");
- ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+ ASSERT_EQ(Tokens.size(), 9u) << Tokens;
EXPECT_TOKEN(Tokens[3], tok::colon, TT_EnumUnderlyingTypeColon);
Tokens = annotate("enum : int { E1 };");
>From ea8251dd0d8932446d6ce464cccba03f0abee5b5 Mon Sep 17 00:00:00 2001
From: Tharun V K <tharunms98 at gmail.com>
Date: Wed, 1 Apr 2026 00:56:22 +0530
Subject: [PATCH 6/7] Add SpaceBeforeEnumUnderlyingTypeColon option
---
clang/docs/ClangFormatStyleOptions.rst | 14 +++++++++++---
clang/include/clang/Format/Format.h | 12 +++++++++---
clang/lib/Format/Format.cpp | 3 +++
clang/lib/Format/TokenAnnotator.cpp | 2 +-
clang/unittests/Format/FormatTest.cpp | 6 +++---
5 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index 69def14d7e371..ec657efe2d5b2 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6831,17 +6831,25 @@ the configuration (without a prefix: ``Auto``).
true: false:
Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
+.. _SpaceBeforeEnumUnderlyingTypeColon:
+
+**SpaceBeforeEnumUnderlyingTypeColon** (``Boolean``) :versionbadge:`clang-format 7` :ref:`¶ <SpaceBeforeEnumUnderlyingTypeColon>`
+ If ``false``, spaces will be removed before enum underlying type colon.
+
+ .. code-block:: c++
+
+ true: false:
+ enum E : int {} enum E: int {}
+
.. _SpaceBeforeInheritanceColon:
**SpaceBeforeInheritanceColon** (``Boolean``) :versionbadge:`clang-format 7` :ref:`¶ <SpaceBeforeInheritanceColon>`
- If ``false``, spaces will be removed before inheritance colon
- and enum underlying type colon.
+ If ``false``, spaces will be removed before inheritance colon.
.. code-block:: c++
true: false:
class Foo : Bar {} vs. class Foo: Bar {}
- enum E : int {} enum E: int {}
.. _SpaceBeforeJsonColon:
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index 9247814a3edf2..c000877049ad8 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5121,14 +5121,20 @@ struct FormatStyle {
/// \version 7
bool SpaceBeforeCtorInitializerColon;
- /// If ``false``, spaces will be removed before inheritance colon
- /// and enum underlying type colon.
+ /// If ``false``, spaces will be removed before enum underlying type colon.
/// \code
/// true: false:
- /// class Foo : Bar {} vs. class Foo: Bar {}
/// enum E : int {} enum E: int {}
/// \endcode
/// \version 7
+ bool SpaceBeforeEnumUnderlyingTypeColon;
+
+ /// If ``false``, spaces will be removed before inheritance colon.
+ /// \code
+ /// true: false:
+ /// class Foo : Bar {} vs. class Foo: Bar {}
+ /// \endcode
+ /// \version 7
bool SpaceBeforeInheritanceColon;
/// If ``true``, a space will be added before a JSON colon. For other
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 2b0aa1735c895..5ca1971acc1ab 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1398,6 +1398,8 @@ template <> struct MappingTraits<FormatStyle> {
Style.SpaceBeforeCpp11BracedList);
IO.mapOptional("SpaceBeforeCtorInitializerColon",
Style.SpaceBeforeCtorInitializerColon);
+ IO.mapOptional("SpaceBeforeEnumUnderlyingTypeColon",
+ Style.SpaceBeforeEnumUnderlyingTypeColon);
IO.mapOptional("SpaceBeforeInheritanceColon",
Style.SpaceBeforeInheritanceColon);
IO.mapOptional("SpaceBeforeJsonColon", Style.SpaceBeforeJsonColon);
@@ -1918,6 +1920,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
LLVMStyle.SpaceBeforeCaseColon = false;
LLVMStyle.SpaceBeforeCpp11BracedList = false;
LLVMStyle.SpaceBeforeCtorInitializerColon = true;
+ LLVMStyle.SpaceBeforeEnumUnderlyingTypeColon = true;
LLVMStyle.SpaceBeforeInheritanceColon = true;
LLVMStyle.SpaceBeforeJsonColon = false;
LLVMStyle.SpaceBeforeParens = FormatStyle::SBPO_ControlStatements;
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 0c185cc08f728..3fa8ec44fa8bf 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5552,7 +5552,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
if (Right.is(TT_InheritanceColon) && !Style.SpaceBeforeInheritanceColon)
return false;
if (Right.is(TT_EnumUnderlyingTypeColon) &&
- !Style.SpaceBeforeInheritanceColon) {
+ !Style.SpaceBeforeEnumUnderlyingTypeColon) {
return false;
}
if (Right.is(TT_RangeBasedForLoopColon) &&
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 3bf20879d1cd2..fbd9e0e0a4da4 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -18632,13 +18632,13 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeColon) {
InvertedSpaceStyle);
}
-TEST_F(FormatTest, EnumUnderlyingTypeUsesInheritanceColonSpacing) {
+TEST_F(FormatTest, EnumUnderlyingTypeColonSpacing) {
FormatStyle Style = getLLVMStyle();
- Style.SpaceBeforeInheritanceColon = true;
+ Style.SpaceBeforeEnumUnderlyingTypeColon = true;
verifyFormat("enum A : int {};", Style);
- Style.SpaceBeforeInheritanceColon = false;
+ Style.SpaceBeforeEnumUnderlyingTypeColon = false;
verifyFormat("enum A: int {};", Style);
}
>From 39545fa998c519bba7e45329021debb2ef3323db Mon Sep 17 00:00:00 2001
From: Tharun V K <tharunms98 at gmail.com>
Date: Wed, 1 Apr 2026 15:56:23 +0530
Subject: [PATCH 7/7] Added parse check for SpaceBeforeEnumUnderlyingTypeColon
---
clang/include/clang/Format/Format.h | 2 +-
clang/unittests/Format/ConfigParseTest.cpp | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index c000877049ad8..48ce5aa2bdfa1 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5126,7 +5126,7 @@ struct FormatStyle {
/// true: false:
/// enum E : int {} enum E: int {}
/// \endcode
- /// \version 7
+ /// \version 23
bool SpaceBeforeEnumUnderlyingTypeColon;
/// If ``false``, spaces will be removed before inheritance colon.
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index 953f57da26cd9..3cff71608cba4 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -219,6 +219,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(SpaceBeforeCaseColon);
CHECK_PARSE_BOOL(SpaceBeforeCpp11BracedList);
CHECK_PARSE_BOOL(SpaceBeforeCtorInitializerColon);
+ CHECK_PARSE_BOOL(SpaceBeforeEnumUnderlyingTypeColon);
CHECK_PARSE_BOOL(SpaceBeforeInheritanceColon);
CHECK_PARSE_BOOL(SpaceBeforeJsonColon);
CHECK_PARSE_BOOL(SpaceBeforeRangeBasedForLoopColon);
More information about the cfe-commits
mailing list