Author: XDeme Date: 2024-02-01T14:11:14-03:00 New Revision: 7e7f118404cdfbee9eaf7c05ab8ea54a25b52aa4
URL: https://github.com/llvm/llvm-project/commit/7e7f118404cdfbee9eaf7c05ab8ea54a25b52aa4 DIFF: https://github.com/llvm/llvm-project/commit/7e7f118404cdfbee9eaf7c05ab8ea54a25b52aa4.diff LOG: [clang-format] Handles Elaborated type specifier for enum in trailing return (#80085) Fixes llvm/llvm-project#80062 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 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 <enum ...". - if (Previous && Previous->is(tok::less)) { + // Ignore if this is part of "template <enum ..." or "... -> 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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits