https://github.com/HazardyKnusperkeks created https://github.com/llvm/llvm-project/pull/70602
Fixes #69325. From 9d3169cbd756f6c3ba9ac2a7e334677c330da3d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= <bjo...@hazardy.de> Date: Sun, 29 Oct 2023 20:55:31 +0100 Subject: [PATCH] [clang-format] Fix annotating annotations after requires clause Fixes #69325. --- clang/lib/Format/TokenAnnotator.cpp | 3 ++- clang/unittests/Format/TokenAnnotatorTest.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index aee966145b8e518..729e7e370bf62ea 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2101,7 +2101,8 @@ class AnnotatingParser { BeforeParen->isNot(TT_TypenameMacro) && BeforeParen->TokenText == BeforeParen->TokenText.upper() && (!BeforeParen->Previous || - BeforeParen->Previous->ClosesTemplateDeclaration)) { + BeforeParen->Previous->ClosesTemplateDeclaration || + BeforeParen->Previous->ClosesRequiresClause)) { Current.setType(TT_FunctionAnnotationRParen); } } diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index c16c7d64752458a..c9f1439e212b0ff 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -1376,6 +1376,20 @@ TEST_F(TokenAnnotatorTest, RequiresDoesNotChangeParsingOfTheRest) { "}"; RequiresTokenCount = 9; TestRequires(__LINE__); + + BaseCode = "template<typename T>\n" + "ANNOTATE(\"S\"\n" + " \"S\")\n" + "void foo();"; + ConstrainedCode = "template<typename T>\n" + " requires(true)\n" + "ANNOTATE(\"S\"\n" + " \"S\")\n" + "void foo();"; + BaseTokenCount = 16; + RequiresTokenCount = 4; + PrefixTokenCount = 5; + TestRequires(__LINE__); } TEST_F(TokenAnnotatorTest, UnderstandsAsm) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits