rymiel created this revision. rymiel added reviewers: HazardyKnusperkeks, owenpan, MyDeveloperDay. Herald added a project: All. rymiel requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This brings the noexcept qualifier more visually in line with the other keyword qualifiers, such as "final" and "override". Originally reported as https://github.com/llvm/llvm-project/issues/44542, it was closed as "working by design" and reinforcing tests were added as part of a218706cba90248be0c60bd6a8f10dbcf0270955 <https://reviews.llvm.org/rGa218706cba90248be0c60bd6a8f10dbcf0270955>. The exact spacing depended on the `PointerAlignment` option, where the default value of `Right` would leave no space. This patch seeks to change this behaviour, regardless of the configured `PointerAlignment` option (matching the previous behaviour of the `Left` option). Closes https://github.com/llvm/llvm-project/issues/59729 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D140767 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ 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 <typename T>\n" "void F(T) && = delete;", getGoogleStyle()); verifyFormat("template <typename T> void operator=(T) &;"); verifyFormat("template <typename T> void operator=(T) const &;"); - verifyFormat("template <typename T> void operator=(T) &noexcept;"); + verifyFormat("template <typename T> void operator=(T) & noexcept;"); verifyFormat("template <typename T> void operator=(T) & = default;"); verifyFormat("template <typename T> void operator=(T) &&;"); verifyFormat("template <typename T> void operator=(T) && = delete;"); @@ -10678,31 +10678,31 @@ verifyFormat("struct f {\n" " template <class T>\n" - " int &foo(const std::string &str) &noexcept {}\n" + " int &foo(const std::string &str) & noexcept {}\n" "};", BreakTemplate); verifyFormat("struct f {\n" " template <class T>\n" - " int &foo(const std::string &str) &&noexcept {}\n" + " int &foo(const std::string &str) && noexcept {}\n" "};", BreakTemplate); verifyFormat("struct f {\n" " template <class T>\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 <class T>\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 <class T>\n" - " auto foo(const std::string &str) &&noexcept -> int & {}\n" + " auto foo(const std::string &str) && noexcept -> int & {}\n" "};", BreakTemplate); Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -3495,7 +3495,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; }
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ 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 <typename T>\n" "void F(T) && = delete;", getGoogleStyle()); verifyFormat("template <typename T> void operator=(T) &;"); verifyFormat("template <typename T> void operator=(T) const &;"); - verifyFormat("template <typename T> void operator=(T) &noexcept;"); + verifyFormat("template <typename T> void operator=(T) & noexcept;"); verifyFormat("template <typename T> void operator=(T) & = default;"); verifyFormat("template <typename T> void operator=(T) &&;"); verifyFormat("template <typename T> void operator=(T) && = delete;"); @@ -10678,31 +10678,31 @@ verifyFormat("struct f {\n" " template <class T>\n" - " int &foo(const std::string &str) &noexcept {}\n" + " int &foo(const std::string &str) & noexcept {}\n" "};", BreakTemplate); verifyFormat("struct f {\n" " template <class T>\n" - " int &foo(const std::string &str) &&noexcept {}\n" + " int &foo(const std::string &str) && noexcept {}\n" "};", BreakTemplate); verifyFormat("struct f {\n" " template <class T>\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 <class T>\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 <class T>\n" - " auto foo(const std::string &str) &&noexcept -> int & {}\n" + " auto foo(const std::string &str) && noexcept -> int & {}\n" "};", BreakTemplate); Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -3495,7 +3495,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; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits