-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclang_format_10.patch
187 lines (181 loc) · 8.25 KB
/
clang_format_10.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 70bcd7048c5..8cb786a4d34 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2176,6 +2176,10 @@ static bool isFunctionDeclarationName(const FormatToken &Current,
Next = Next->Next;
continue;
}
+ if (Next->is(TT_TemplateOpener) && Next->MatchingParen) {
+ Next = Next->MatchingParen;
+ continue;
+ }
break;
}
@@ -2705,20 +2709,40 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
tok::l_square));
if (Right.is(tok::star) && Left.is(tok::l_paren))
return false;
- if (Right.isOneOf(tok::star, tok::amp, tok::ampamp) &&
- (Left.is(tok::identifier) || Left.isSimpleTypeSpecifier()) &&
- // Space between the type and the * in:
- // operator void*()
- // operator char*()
- // operator /*comment*/ const char*()
- // operator volatile /*comment*/ char*()
- // operator Foo*()
- // dependent on PointerAlignment style.
- Left.Previous &&
- (Left.Previous->endsSequence(tok::kw_operator) ||
- Left.Previous->endsSequence(tok::kw_const, tok::kw_operator) ||
- Left.Previous->endsSequence(tok::kw_volatile, tok::kw_operator)))
- return (Style.PointerAlignment != FormatStyle::PAS_Left);
+ if (Right.is(tok::star) && Left.is(tok::star))
+ return false;
+ if (Right.isOneOf(tok::star, tok::amp, tok::ampamp)) {
+ const FormatToken *Previous = &Left;
+ while (Previous && !Previous->is(tok::kw_operator)) {
+ if (Previous->is(tok::identifier) || Previous->isSimpleTypeSpecifier()) {
+ Previous = Previous->getPreviousNonComment();
+ continue;
+ }
+ if (Previous->is(TT_TemplateCloser) && Previous->MatchingParen) {
+ Previous = Previous->MatchingParen->getPreviousNonComment();
+ continue;
+ }
+ if (Previous->is(tok::coloncolon)) {
+ Previous = Previous->getPreviousNonComment();
+ continue;
+ }
+ break;
+ }
+ // Space between the type and the * in:
+ // operator void*()
+ // operator char*()
+ // operator /*comment*/ const char*()
+ // operator volatile /*comment*/ char*()
+ // operator Foo*()
+ // operator C<T>*()
+ // operator std::Foo*()
+ // operator C<T>::D<U>*()
+ // dependent on PointerAlignment style.
+ if (Previous && (Previous->endsSequence(tok::kw_operator) ||
+ Previous->endsSequence(tok::kw_const, tok::kw_operator) ||
+ Previous->endsSequence(tok::kw_volatile, tok::kw_operator)))
+ return (Style.PointerAlignment != FormatStyle::PAS_Left);
+ }
const auto SpaceRequiredForArrayInitializerLSquare =
[](const FormatToken &LSquareTok, const FormatStyle &Style) {
return Style.SpacesInContainerLiterals ||
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index a5a26b5c1e8..7f8a3795e6e 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -6185,7 +6185,17 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
"void\n"
"A::operator[]() {}\n"
"void\n"
- "A::operator!() {}\n",
+ "A::operator!() {}\n"
+ "void\n"
+ "A::operator**() {}\n"
+ "void\n"
+ "A::operator<Foo> *() {}\n"
+ "void\n"
+ "A::operator<Foo> **() {}\n"
+ "void\n"
+ "A::operator<Foo> &() {}\n"
+ "void\n"
+ "A::operator void **() {}\n",
Style);
verifyFormat("constexpr auto\n"
"operator()() const -> reference {}\n"
@@ -6202,6 +6212,10 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
"constexpr auto\n"
"operator void *() const -> reference {}\n"
"constexpr auto\n"
+ "operator void **() const -> reference {}\n"
+ "constexpr auto\n"
+ "operator void *() const -> reference {}\n"
+ "constexpr auto\n"
"operator void &() const -> reference {}\n"
"constexpr auto\n"
"operator void &&() const -> reference {}\n"
@@ -14986,9 +15000,20 @@ TEST_F(FormatTest, OperatorSpacing) {
Style.PointerAlignment = FormatStyle::PAS_Right;
verifyFormat("Foo::operator*();", Style);
verifyFormat("Foo::operator void *();", Style);
+ verifyFormat("Foo::operator void **();", Style);
verifyFormat("Foo::operator()(void *);", Style);
verifyFormat("Foo::operator*(void *);", Style);
verifyFormat("Foo::operator*();", Style);
+ verifyFormat("Foo::operator**();", Style);
+ verifyFormat("Foo::operator&();", Style);
+ verifyFormat("Foo::operator<int> *();", Style);
+ verifyFormat("Foo::operator<Foo> *();", Style);
+ verifyFormat("Foo::operator<int> **();", Style);
+ verifyFormat("Foo::operator<Foo> **();", Style);
+ verifyFormat("Foo::operator<int> &();", Style);
+ verifyFormat("Foo::operator<Foo> &();", Style);
+ verifyFormat("Foo::operator<int> &&();", Style);
+ verifyFormat("Foo::operator<Foo> &&();", Style);
verifyFormat("operator*(int (*)(), class Foo);", Style);
verifyFormat("Foo::operator&();", Style);
@@ -14999,21 +15024,39 @@ TEST_F(FormatTest, OperatorSpacing) {
verifyFormat("operator&(int (&)(), class Foo);", Style);
verifyFormat("Foo::operator&&();", Style);
+ verifyFormat("Foo::operator**();", Style);
verifyFormat("Foo::operator void &&();", Style);
verifyFormat("Foo::operator()(void &&);", Style);
verifyFormat("Foo::operator&&(void &&);", Style);
verifyFormat("Foo::operator&&();", Style);
verifyFormat("operator&&(int(&&)(), class Foo);", Style);
+ verifyFormat("operator const nsTArrayRight<E> &()", Style);
+ verifyFormat("[[nodiscard]] operator const nsTArrayRight<E, Allocator> &()",
+ Style);
+ verifyFormat("operator void **()", Style);
+ verifyFormat("operator const FooRight<Object> &()", Style);
+ verifyFormat("operator const FooRight<Object> *()", Style);
+ verifyFormat("operator const FooRight<Object> **()", Style);
Style.PointerAlignment = FormatStyle::PAS_Left;
verifyFormat("Foo::operator*();", Style);
+ verifyFormat("Foo::operator**();", Style);
verifyFormat("Foo::operator void*();", Style);
+ verifyFormat("Foo::operator void**();", Style);
verifyFormat("Foo::operator/*comment*/ void*();", Style);
verifyFormat("Foo::operator/*a*/ const /*b*/ void*();", Style);
verifyFormat("Foo::operator/*a*/ volatile /*b*/ void*();", Style);
verifyFormat("Foo::operator()(void*);", Style);
verifyFormat("Foo::operator*(void*);", Style);
verifyFormat("Foo::operator*();", Style);
+ verifyFormat("Foo::operator<int>*();", Style);
+ verifyFormat("Foo::operator<Foo>*();", Style);
+ verifyFormat("Foo::operator<int>**();", Style);
+ verifyFormat("Foo::operator<Foo>**();", Style);
+ verifyFormat("Foo::operator<int>&();", Style);
+ verifyFormat("Foo::operator<Foo>&();", Style);
+ verifyFormat("Foo::operator<int>&&();", Style);
+ verifyFormat("Foo::operator<Foo>&&();", Style);
verifyFormat("operator*(int (*)(), class Foo);", Style);
verifyFormat("Foo::operator&();", Style);
@@ -15035,6 +15078,21 @@ TEST_F(FormatTest, OperatorSpacing) {
verifyFormat("Foo::operator&&(void&&);", Style);
verifyFormat("Foo::operator&&();", Style);
verifyFormat("operator&&(int(&&)(), class Foo);", Style);
+ verifyFormat("operator const nsTArrayLeft<E>&()", Style);
+ verifyFormat("[[nodiscard]] operator const nsTArrayLeft<E, Allocator>&()",
+ Style);
+ verifyFormat("operator void**()", Style);
+ verifyFormat("operator const FooLeft<Object>&()", Style);
+ verifyFormat("operator const FooLeft<Object>*()", Style);
+ verifyFormat("operator const FooLeft<Object>**()", Style);
+
+ // PR45107
+ verifyFormat("operator Vector<String>&();", Style);
+ verifyFormat("operator const Vector<String>&();", Style);
+ verifyFormat("operator foo::Bar*();", Style);
+ verifyFormat("operator const Foo<X>::Bar<Y>*();", Style);
+ verifyFormat("operator/*a*/ const /*b*/ Foo /*c*/<X> /*d*/ ::Bar<Y>*();",
+ Style);
Style.PointerAlignment = FormatStyle::PAS_Middle;
verifyFormat("Foo::operator*();", Style);