[clang] c609043 - [clang-format] Don't allow comma in front of structural enum (#91056)
via cfe-commits
cfe-commits at lists.llvm.org
Sun May 5 20:44:18 PDT 2024
Author: Emilia Kond
Date: 2024-05-06T06:44:13+03:00
New Revision: c609043dd00955bf177ff57b0bad2a87c1e61a36
URL: https://github.com/llvm/llvm-project/commit/c609043dd00955bf177ff57b0bad2a87c1e61a36
DIFF: https://github.com/llvm/llvm-project/commit/c609043dd00955bf177ff57b0bad2a87c1e61a36.diff
LOG: [clang-format] Don't allow comma in front of structural enum (#91056)
Assume that a comma in front of `enum` means it is actually a part of an
elaborated type in a template parameter list.
Fixes https://github.com/llvm/llvm-project/issues/47782
Added:
Modified:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index e8a8dd58d07eea..b5415fa9ecab55 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1763,8 +1763,9 @@ void UnwrappedLineParser::parseStructuralElement(
break;
}
case tok::kw_enum:
- // Ignore if this is part of "template <enum ..." or "... -> enum".
- if (Previous && Previous->isOneOf(tok::less, tok::arrow)) {
+ // Ignore if this is part of "template <enum ..." or "... -> enum" or
+ // "template <..., enum ...>".
+ if (Previous && Previous->isOneOf(tok::less, tok::arrow, tok::comma)) {
nextToken();
break;
}
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 01daf8dee505bc..b424424b85777b 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -489,6 +489,10 @@ TEST_F(TokenAnnotatorTest, UnderstandsStructs) {
EXPECT_TOKEN(Tokens[24], tok::amp, TT_UnaryOperator);
EXPECT_TOKEN(Tokens[27], tok::l_square, TT_ArraySubscriptLSquare);
EXPECT_TOKEN(Tokens[32], tok::r_brace, TT_StructRBrace);
+
+ Tokens = annotate("template <typename T, enum E e> struct S {};");
+ ASSERT_EQ(Tokens.size(), 15u) << Tokens;
+ EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_StructLBrace);
}
TEST_F(TokenAnnotatorTest, UnderstandsUnions) {
More information about the cfe-commits
mailing list