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 @@ -1924,7 +1924,7 @@ !Current.Next->isBinaryOperator() && !Current.Next->isOneOf(tok::semi, tok::colon, tok::l_brace, tok::comma, tok::period, tok::arrow, - tok::coloncolon)) { + tok::coloncolon, tok::kw_noexcept)) { if (FormatToken *AfterParen = Current.MatchingParen->Next) { // Make sure this isn't the return type of an Obj-C block declaration if (AfterParen->isNot(tok::caret)) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -9607,6 +9607,15 @@ verifyFormat("template // T can be A, B or C.\n" "struct C {};", AlwaysBreak); + verifyFormat("template \n" + "C(T) noexcept;", + AlwaysBreak); + verifyFormat("template \n" + "ClassName(T) noexcept;", + AlwaysBreak); + verifyFormat("template \n" + "POOR_NAME(T) noexcept;", + AlwaysBreak); verifyFormat("template class A {\n" "public:\n" " E *f();\n" @@ -9617,6 +9626,9 @@ verifyFormat("template class C {};", NeverBreak); verifyFormat("template void f();", NeverBreak); verifyFormat("template void f() {}", NeverBreak); + verifyFormat("template C(T) noexcept;", NeverBreak); + verifyFormat("template ClassName(T) noexcept;", NeverBreak); + verifyFormat("template POOR_NAME(T) noexcept;", NeverBreak); verifyFormat("template \nvoid foo(aaaaaaaaaaaaaaaaaaaaaaaaaa " "bbbbbbbbbbbbbbbbbbbb) {}", NeverBreak); 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 @@ -788,6 +788,19 @@ EXPECT_TOKEN(Tokens[7], tok::l_brace, TT_LambdaLBrace); } +TEST_F(TokenAnnotatorTest, UnderstandsFunctionAnnotations) { + auto Tokens = annotate("template \n" + "DEPRECATED(\"Use NewClass::NewFunction instead.\")\n" + "string OldFunction(const string ¶meter) {}"); + ASSERT_EQ(Tokens.size(), 20u) << Tokens; + EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_FunctionAnnotationRParen); + + Tokens = annotate("template \n" + "A(T) noexcept;"); + ASSERT_EQ(Tokens.size(), 12u) << Tokens; + EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_Unknown); +} + TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) { auto Annotate = [this](llvm::StringRef Code) { return annotate(Code, getLLVMStyle(FormatStyle::LK_Verilog));