llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-format Author: Björn Schäpers (HazardyKnusperkeks) <details> <summary>Changes</summary> At this point we can't (or won't) decide wether this is a template argument or just an expression, opt out of the specialized (and in the test cases wrong) assignment. Fixes #<!-- -->212622 --- Full diff: https://github.com/llvm/llvm-project/pull/212856.diff 2 Files Affected: - (modified) clang/lib/Format/UnwrappedLineParser.cpp (+18-3) - (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+12) ``````````diff diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 8e6f7e2f2ce07..e9061b15c638f 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -2663,7 +2663,8 @@ bool UnwrappedLineParser::parseBracedList(bool IsAngleBracket, bool IsEnum) { /// Parses a pair of parentheses (and everything between them). /// \param StarAndAmpTokenType If different than TT_Unknown sets this type for /// all (double) ampersands and stars. This applies for all nested scopes as -/// well. +/// well, this is disabled within a (potential) template argument <>, and thus +/// also if we find only a <. /// /// Returns whether there is a `=` token between the parentheses. bool UnwrappedLineParser::parseParens(TokenType StarAndAmpTokenType, @@ -2674,6 +2675,7 @@ bool UnwrappedLineParser::parseParens(TokenType StarAndAmpTokenType, bool SeenComma = false; bool SeenEqual = false; bool MightBeFoldExpr = false; + auto ExcessLess = 0; nextToken(); const bool MightBeStmtExpr = FormatTok->is(tok::l_brace); if (!InMacroCall && Prev && Prev->is(TT_FunctionLikeMacro)) @@ -2681,8 +2683,10 @@ bool UnwrappedLineParser::parseParens(TokenType StarAndAmpTokenType, do { switch (FormatTok->Tok.getKind()) { case tok::l_paren: - if (parseParens(StarAndAmpTokenType, InMacroCall)) + if (parseParens(ExcessLess == 0 ? StarAndAmpTokenType : TT_Unknown, + InMacroCall)) { SeenEqual = true; + } if (Style.isJava() && FormatTok->is(tok::l_brace)) parseChildBlock(); break; @@ -2799,10 +2803,21 @@ bool UnwrappedLineParser::parseParens(TokenType StarAndAmpTokenType, case tok::kw_requires: parseRequiresExpression(); break; + case tok::less: + // We have here no clue wether this is a less, or a template opener, opt + // out of the predefined StarAndAmpTokenType. + ++ExcessLess; + nextToken(); + break; + case tok::greater: + if (ExcessLess > 1) + --ExcessLess; + nextToken(); + break; case tok::star: case tok::amp: case tok::ampamp: - if (StarAndAmpTokenType != TT_Unknown) + if (StarAndAmpTokenType != TT_Unknown && ExcessLess == 0) FormatTok->setFinalizedType(StarAndAmpTokenType); [[fallthrough]]; default: diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index ad8a4795cd2db..ae9e0b6b8e74c 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -1579,6 +1579,18 @@ TEST_F(TokenAnnotatorTest, UnderstandsRequiresClausesAndConcepts) { ASSERT_EQ(Tokens.size(), 18u) << Tokens; EXPECT_TOKEN(Tokens[7], tok::kw_requires, TT_RequiresClause); EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_FunctionLBrace); + + Tokens = annotate("template <typename T>\n" + " requires(is_convertible_v<const T&, Foo>)" + "void foo(T) {}"); + ASSERT_EQ(Tokens.size(), 24u) << Tokens; + EXPECT_TOKEN(Tokens[11], tok::amp, TT_PointerOrReference); + + Tokens = annotate("template <typename T>\n" + " requires(is_convertible_v<(const T&), Foo>)" + "void foo(T) {}"); + ASSERT_EQ(Tokens.size(), 26u) << Tokens; + EXPECT_TOKEN(Tokens[12], tok::amp, TT_PointerOrReference); } TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) { `````````` </details> https://github.com/llvm/llvm-project/pull/212856 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
