[clang] 54fab18 - [clang-format] Require space before noexcept qualifier
Emilia Dreamer via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 5 19:08:54 PST 2023
Author: Emilia Dreamer
Date: 2023-01-06T05:03:56+02:00
New Revision: 54fab18cedace085344b674ab9de2c93b5fa479b
URL: https://github.com/llvm/llvm-project/commit/54fab18cedace085344b674ab9de2c93b5fa479b
DIFF: https://github.com/llvm/llvm-project/commit/54fab18cedace085344b674ab9de2c93b5fa479b.diff
LOG: [clang-format] Require space before noexcept qualifier
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. 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
Reviewed By: HazardyKnusperkeks, owenpan, MyDeveloperDay
Differential Revision: https://reviews.llvm.org/D140767
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 3ed0b3d3c6612..35fa8cf91b330 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3530,7 +3530,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
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
index 2265b03f0868a..843e945aeae5b 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -10566,10 +10566,10 @@ TEST_F(FormatTest, UnderstandsOverloadedOperators) {
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 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
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 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) {
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);
More information about the cfe-commits
mailing list