diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1110,7 +1110,7 @@ !Contexts.back().IsExpression && !Line.startsWith(TT_ObjCProperty) && !Tok->isOneOf(TT_TypeDeclarationParen, TT_RequiresExpressionLParen) && (!Tok->Previous || - !Tok->Previous->isOneOf(tok::kw___attribute, + !Tok->Previous->isOneOf(tok::kw___attribute, TT_RequiresClause, TT_LeadingJavaAnnotation))) { Line.MightBeFunctionDecl = true; } diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -728,6 +728,16 @@ BaseTokenCount = 26; TestRequires(__LINE__); + BaseCode = "template\n" + "T foo();"; + ConstrainedCode = "template\n" + " requires(Foo)\n" + "T foo();"; + BaseTokenCount = 11; + RequiresTokenCount = 7; + PrefixTokenCount = 5; + TestRequires(__LINE__); + BaseCode = "template\n" "Bar(T) -> Bar;"; ConstrainedCode = "template\n"