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 @@ -3530,7 +3530,8 @@ if (Right.is(TT_BlockComment)) return true; // foo() -> const Bar * override/final - if (Right.isOneOf(Keywords.kw_override, Keywords.kw_final) && + if (Right.isOneOf(Keywords.kw_override, Keywords.kw_final, + tok::kw_noexcept) && !Right.is(TT_StartOfName)) { return true; } 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 @@ -10566,10 +10566,10 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) { verifyFormat("void A::b() && {}"); - verifyFormat("void A::b() &&noexcept {}"); + verifyFormat("void A::b() && noexcept {}"); verifyFormat("Deleted &operator=(const Deleted &) & = default;"); verifyFormat("Deleted &operator=(const Deleted &) && = delete;"); - verifyFormat("Deleted &operator=(const Deleted &) &noexcept = default;"); + verifyFormat("Deleted &operator=(const Deleted &) & noexcept = default;"); verifyFormat("SomeType MemberFunction(const Deleted &) & = delete;"); verifyFormat("SomeType MemberFunction(const Deleted &) && = delete;"); verifyFormat("Deleted &operator=(const Deleted &) &;"); @@ -10579,16 +10579,16 @@ verifyFormat("SomeType MemberFunction(const Deleted &) && {}"); verifyFormat("SomeType MemberFunction(const Deleted &) && final {}"); verifyFormat("SomeType MemberFunction(const Deleted &) && override {}"); - verifyFormat("SomeType MemberFunction(const Deleted &) &&noexcept {}"); + verifyFormat("SomeType MemberFunction(const Deleted &) && noexcept {}"); verifyFormat("void Fn(T const &) const &;"); verifyFormat("void Fn(T const volatile &&) const volatile &&;"); - verifyFormat("void Fn(T const volatile &&) const volatile &&noexcept;"); + verifyFormat("void Fn(T const volatile &&) const volatile && noexcept;"); verifyFormat("template \n" "void F(T) && = delete;", getGoogleStyle()); verifyFormat("template void operator=(T) &;"); verifyFormat("template void operator=(T) const &;"); - verifyFormat("template void operator=(T) &noexcept;"); + verifyFormat("template void operator=(T) & noexcept;"); verifyFormat("template void operator=(T) & = default;"); verifyFormat("template void operator=(T) &&;"); verifyFormat("template void operator=(T) && = delete;"); @@ -10678,31 +10678,31 @@ verifyFormat("struct f {\n" " template \n" - " int &foo(const std::string &str) &noexcept {}\n" + " int &foo(const std::string &str) & noexcept {}\n" "};", BreakTemplate); verifyFormat("struct f {\n" " template \n" - " int &foo(const std::string &str) &&noexcept {}\n" + " int &foo(const std::string &str) && noexcept {}\n" "};", BreakTemplate); verifyFormat("struct f {\n" " template \n" - " int &foo(const std::string &str) const &noexcept {}\n" + " int &foo(const std::string &str) const & noexcept {}\n" "};", BreakTemplate); verifyFormat("struct f {\n" " template \n" - " int &foo(const std::string &str) const &noexcept {}\n" + " int &foo(const std::string &str) const & noexcept {}\n" "};", BreakTemplate); verifyFormat("struct f {\n" " template \n" - " auto foo(const std::string &str) &&noexcept -> int & {}\n" + " auto foo(const std::string &str) && noexcept -> int & {}\n" "};", BreakTemplate);