[PATCH] D139801: [clang-format] Adds 'friend' to QualifierOrder.
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 22 02:04:30 PST 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4cafc3727b35: [clang-format] Add 'friend' to QualifierOrder (authored by red1bluelost, committed by owenpan).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D139801/new/
https://reviews.llvm.org/D139801
Files:
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h
clang/lib/Format/QualifierAlignmentFixer.cpp
clang/unittests/Format/QualifierFixerTest.cpp
Index: clang/unittests/Format/QualifierFixerTest.cpp
===================================================================
--- clang/unittests/Format/QualifierFixerTest.cpp
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -133,6 +133,8 @@
tok::kw_static);
EXPECT_EQ(LeftRightQualifierAlignmentFixer::getTokenFromQualifier("restrict"),
tok::kw_restrict);
+ EXPECT_EQ(LeftRightQualifierAlignmentFixer::getTokenFromQualifier("friend"),
+ tok::kw_friend);
}
TEST_F(QualifierFixerTest, FailQualifierInvalidConfiguration) {
@@ -196,8 +198,8 @@
TEST_F(QualifierFixerTest, QualifiersCustomOrder) {
FormatStyle Style = getLLVMStyle();
Style.QualifierAlignment = FormatStyle::QAS_Left;
- Style.QualifierOrder = {"inline", "constexpr", "static",
- "const", "volatile", "type"};
+ Style.QualifierOrder = {"friend", "inline", "constexpr", "static",
+ "const", "volatile", "type"};
verifyFormat("const volatile int a;", "const volatile int a;", Style);
verifyFormat("const volatile int a;", "volatile const int a;", Style);
@@ -216,6 +218,15 @@
verifyFormat("constexpr static LPINT Bar;", "static constexpr LPINT Bar;",
Style);
verifyFormat("const const int a;", "const int const a;", Style);
+
+ verifyFormat(
+ "friend constexpr auto operator<=>(const foo &, const foo &) = default;",
+ "constexpr friend auto operator<=>(const foo &, const foo &) = default;",
+ Style);
+ verifyFormat(
+ "friend constexpr bool operator==(const foo &, const foo &) = default;",
+ "constexpr bool friend operator==(const foo &, const foo &) = default;",
+ Style);
}
TEST_F(QualifierFixerTest, LeftRightQualifier) {
@@ -723,9 +734,10 @@
ConfiguredTokens.push_back(tok::kw_inline);
ConfiguredTokens.push_back(tok::kw_restrict);
ConfiguredTokens.push_back(tok::kw_constexpr);
+ ConfiguredTokens.push_back(tok::kw_friend);
- auto Tokens =
- annotate("const static inline auto restrict int double long constexpr");
+ auto Tokens = annotate(
+ "const static inline auto restrict int double long constexpr friend");
EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isQualifierOrType(
Tokens[0], ConfiguredTokens));
@@ -745,6 +757,8 @@
Tokens[7], ConfiguredTokens));
EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isQualifierOrType(
Tokens[8], ConfiguredTokens));
+ EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isQualifierOrType(
+ Tokens[9], ConfiguredTokens));
auto NotTokens = annotate("for while do Foo Bar ");
Index: clang/lib/Format/QualifierAlignmentFixer.cpp
===================================================================
--- clang/lib/Format/QualifierAlignmentFixer.cpp
+++ clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -414,6 +414,7 @@
.Case("inline", tok::kw_inline)
.Case("constexpr", tok::kw_constexpr)
.Case("restrict", tok::kw_restrict)
+ .Case("friend", tok::kw_friend)
.Default(tok::identifier);
}
Index: clang/include/clang/Format/Format.h
===================================================================
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -2970,6 +2970,7 @@
/// * const
/// * inline
/// * static
+ /// * friend
/// * constexpr
/// * volatile
/// * restrict
Index: clang/docs/ClangFormatStyleOptions.rst
===================================================================
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -3712,6 +3712,7 @@
* const
* inline
* static
+ * friend
* constexpr
* volatile
* restrict
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139801.484771.patch
Type: text/x-patch
Size: 3732 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221222/6867b1a7/attachment.bin>
More information about the cfe-commits
mailing list