Author: Björn Schäpers Date: 2023-10-31T13:10:46+01:00 New Revision: c280bed85a8b9cd6ebf48f9f2923890edc7039f0
URL: https://github.com/llvm/llvm-project/commit/c280bed85a8b9cd6ebf48f9f2923890edc7039f0 DIFF: https://github.com/llvm/llvm-project/commit/c280bed85a8b9cd6ebf48f9f2923890edc7039f0.diff LOG: [clang-format] Fix annotating annotations after requires clause Fixes #69325. Added: Modified: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/TokenAnnotatorTest.cpp Removed: ################################################################################ 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