From 7e7f118404cdfbee9eaf7c05ab8ea54a25b52aa4 Mon Sep 17 00:00:00 2001 From: XDeme Date: Thu, 1 Feb 2024 14:11:14 -0300 Subject: [PATCH] [clang-format] Handles Elaborated type specifier for enum in trailing return (#80085) Fixes llvm/llvm-project#80062 --- clang/lib/Format/UnwrappedLineParser.cpp | 4 ++-- clang/unittests/Format/TokenAnnotatorTest.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 0a7f8808f29af..d4f9b3f9df524 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -1760,8 +1760,8 @@ void UnwrappedLineParser::parseStructuralElement( break; } case tok::kw_enum: - // Ignore if this is part of "template is(tok::less)) { + // Ignore if this is part of "template enum". + if (Previous && Previous->isOneOf(tok::less, tok::arrow)) { nextToken(); break; } diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 6e5832858c1ec..52a00c8a1a35d 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -2644,6 +2644,12 @@ TEST_F(TokenAnnotatorTest, StreamOperator) { EXPECT_TRUE(Tokens[5]->MustBreakBefore); } +TEST_F(TokenAnnotatorTest, UnderstandsElaboratedTypeSpecifier) { + auto Tokens = annotate("auto foo() -> enum En {}"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; + EXPECT_TOKEN(Tokens[7], tok::l_brace, TT_FunctionLBrace); +} + } // namespace } // namespace format } // namespace clang