@@ -45,15 +45,62 @@ TEST(SmartPointerAccessorCachingTest, MatchesClassWithStarArrowGet) {
45
45
EXPECT_TRUE (matches (Decls,
46
46
" int target(std::unique_ptr<S> P) { return (*P).i; }" ,
47
47
isSmartPointerLikeOperatorStar ()));
48
+ EXPECT_TRUE (matches (Decls,
49
+ " int target(std::unique_ptr<S> P) { return (*P).i; }" ,
50
+ isPointerLikeOperatorStar ()));
51
+
48
52
EXPECT_TRUE (matches (Decls,
49
53
" int target(std::unique_ptr<S> P) { return P->i; }" ,
50
54
isSmartPointerLikeOperatorArrow ()));
55
+ EXPECT_TRUE (matches (Decls,
56
+ " int target(std::unique_ptr<S> P) { return P->i; }" ,
57
+ isPointerLikeOperatorArrow ()));
58
+
51
59
EXPECT_TRUE (matches (Decls,
52
60
" int target(std::unique_ptr<S> P) { return P.get()->i; }" ,
53
61
isSmartPointerLikeGetMethodCall ()));
54
62
55
63
EXPECT_TRUE (matches (Decls, " int target(UniquePtrAlias<S> P) { return P->i; }" ,
56
64
isSmartPointerLikeOperatorArrow ()));
65
+ EXPECT_TRUE (matches (Decls, " int target(UniquePtrAlias<S> P) { return P->i; }" ,
66
+ isPointerLikeOperatorArrow ()));
67
+ }
68
+
69
+ TEST (SmartPointerAccessorCachingTest, MatchesClassWithStarArrow) {
70
+ llvm::StringRef Decls (R"cc(
71
+ namespace std {
72
+ template <class T>
73
+ struct unique_ptr {
74
+ T* operator->() const;
75
+ T& operator*() const;
76
+ };
77
+ } // namespace std
78
+
79
+ template <class T>
80
+ using UniquePtrAlias = std::unique_ptr<T>;
81
+
82
+ struct S { int i; };
83
+ )cc" );
84
+
85
+ EXPECT_FALSE (matches (Decls,
86
+ " int target(std::unique_ptr<S> P) { return (*P).i; }" ,
87
+ isSmartPointerLikeOperatorStar ()));
88
+ EXPECT_TRUE (matches (Decls,
89
+ " int target(std::unique_ptr<S> P) { return (*P).i; }" ,
90
+ isPointerLikeOperatorStar ()));
91
+
92
+ EXPECT_FALSE (matches (Decls,
93
+ " int target(std::unique_ptr<S> P) { return P->i; }" ,
94
+ isSmartPointerLikeOperatorArrow ()));
95
+ EXPECT_TRUE (matches (Decls,
96
+ " int target(std::unique_ptr<S> P) { return P->i; }" ,
97
+ isPointerLikeOperatorArrow ()));
98
+
99
+ EXPECT_FALSE (matches (Decls,
100
+ " int target(UniquePtrAlias<S> P) { return P->i; }" ,
101
+ isSmartPointerLikeOperatorArrow ()));
102
+ EXPECT_TRUE (matches (Decls, " int target(UniquePtrAlias<S> P) { return P->i; }" ,
103
+ isPointerLikeOperatorArrow ()));
57
104
}
58
105
59
106
TEST (SmartPointerAccessorCachingTest, NoMatchIfUnexpectedReturnTypes) {
@@ -75,15 +122,25 @@ TEST(SmartPointerAccessorCachingTest, NoMatchIfUnexpectedReturnTypes) {
75
122
EXPECT_FALSE (matches (Decls,
76
123
" int target(std::unique_ptr<S, T> P) { return (*P).i; }" ,
77
124
isSmartPointerLikeOperatorStar ()));
125
+ EXPECT_FALSE (matches (Decls,
126
+ " int target(std::unique_ptr<S, T> P) { return (*P).i; }" ,
127
+ isPointerLikeOperatorStar ()));
128
+
78
129
EXPECT_FALSE (matches (Decls,
79
130
" int target(std::unique_ptr<S, T> P) { return P->j; }" ,
80
131
isSmartPointerLikeOperatorArrow ()));
132
+ EXPECT_FALSE (matches (Decls,
133
+ " int target(std::unique_ptr<S, T> P) { return P->j; }" ,
134
+ isPointerLikeOperatorArrow ()));
81
135
// The class matching arguably accidentally matches, just because the
82
136
// instantiation is with S, S. Hopefully doesn't happen too much in real code
83
137
// with such operator* and operator-> overloads.
84
138
EXPECT_TRUE (matches (Decls,
85
139
" int target(std::unique_ptr<S, S> P) { return P->i; }" ,
86
140
isSmartPointerLikeOperatorArrow ()));
141
+ EXPECT_TRUE (matches (Decls,
142
+ " int target(std::unique_ptr<S, S> P) { return P->i; }" ,
143
+ isPointerLikeOperatorArrow ()));
87
144
}
88
145
89
146
TEST (SmartPointerAccessorCachingTest, NoMatchIfBinaryStar) {
@@ -103,6 +160,9 @@ TEST(SmartPointerAccessorCachingTest, NoMatchIfBinaryStar) {
103
160
EXPECT_FALSE (
104
161
matches (Decls, " int target(std::unique_ptr<S> P) { return (P * 10).i; }" ,
105
162
isSmartPointerLikeOperatorStar ()));
163
+ EXPECT_FALSE (
164
+ matches (Decls, " int target(std::unique_ptr<S> P) { return (P * 10).i; }" ,
165
+ isPointerLikeOperatorStar ()));
106
166
}
107
167
108
168
TEST (SmartPointerAccessorCachingTest, NoMatchIfNoConstOverloads) {
@@ -122,9 +182,17 @@ TEST(SmartPointerAccessorCachingTest, NoMatchIfNoConstOverloads) {
122
182
EXPECT_FALSE (matches (Decls,
123
183
" int target(std::unique_ptr<S> P) { return (*P).i; }" ,
124
184
isSmartPointerLikeOperatorStar ()));
185
+ EXPECT_FALSE (matches (Decls,
186
+ " int target(std::unique_ptr<S> P) { return (*P).i; }" ,
187
+ isPointerLikeOperatorStar ()));
188
+
125
189
EXPECT_FALSE (matches (Decls,
126
190
" int target(std::unique_ptr<S> P) { return P->i; }" ,
127
191
isSmartPointerLikeOperatorArrow ()));
192
+ EXPECT_FALSE (matches (Decls,
193
+ " int target(std::unique_ptr<S> P) { return P->i; }" ,
194
+ isPointerLikeOperatorArrow ()));
195
+
128
196
EXPECT_FALSE (
129
197
matches (Decls, " int target(std::unique_ptr<S> P) { return P.get()->i; }" ,
130
198
isSmartPointerLikeGetMethodCall ()));
@@ -146,6 +214,10 @@ TEST(SmartPointerAccessorCachingTest, NoMatchIfNoStarMethod) {
146
214
EXPECT_FALSE (matches (Decls,
147
215
" int target(std::unique_ptr<S> P) { return P->i; }" ,
148
216
isSmartPointerLikeOperatorArrow ()));
217
+ EXPECT_FALSE (matches (Decls,
218
+ " int target(std::unique_ptr<S> P) { return P->i; }" ,
219
+ isPointerLikeOperatorArrow ()));
220
+
149
221
EXPECT_FALSE (matches (Decls,
150
222
" int target(std::unique_ptr<S> P) { return P->i; }" ,
151
223
isSmartPointerLikeGetMethodCall ()));
@@ -171,15 +243,31 @@ TEST(SmartPointerAccessorCachingTest, MatchesWithValueAndNonConstOverloads) {
171
243
EXPECT_TRUE (matches (
172
244
Decls, " int target(std::optional<S> &NonConst) { return (*NonConst).i; }" ,
173
245
isSmartPointerLikeOperatorStar ()));
246
+ EXPECT_TRUE (matches (
247
+ Decls, " int target(std::optional<S> &NonConst) { return (*NonConst).i; }" ,
248
+ isPointerLikeOperatorStar ()));
249
+
174
250
EXPECT_TRUE (matches (
175
251
Decls, " int target(const std::optional<S> &Const) { return (*Const).i; }" ,
176
252
isSmartPointerLikeOperatorStar ()));
253
+ EXPECT_TRUE (matches (
254
+ Decls, " int target(const std::optional<S> &Const) { return (*Const).i; }" ,
255
+ isPointerLikeOperatorStar ()));
256
+
177
257
EXPECT_TRUE (matches (
178
258
Decls, " int target(std::optional<S> &NonConst) { return NonConst->i; }" ,
179
259
isSmartPointerLikeOperatorArrow ()));
260
+ EXPECT_TRUE (matches (
261
+ Decls, " int target(std::optional<S> &NonConst) { return NonConst->i; }" ,
262
+ isPointerLikeOperatorArrow ()));
263
+
180
264
EXPECT_TRUE (matches (
181
265
Decls, " int target(const std::optional<S> &Const) { return Const->i; }" ,
182
266
isSmartPointerLikeOperatorArrow ()));
267
+ EXPECT_TRUE (matches (
268
+ Decls, " int target(const std::optional<S> &Const) { return Const->i; }" ,
269
+ isPointerLikeOperatorArrow ()));
270
+
183
271
EXPECT_TRUE (matches (
184
272
Decls,
185
273
" int target(std::optional<S> &NonConst) { return NonConst.value().i; }" ,
@@ -214,16 +302,34 @@ TEST(SmartPointerAccessorCachingTest, MatchesWithTypeAliases) {
214
302
Decls,
215
303
" int target(HasGetAndValue<S> &NonConst) { return (*NonConst).i; }" ,
216
304
isSmartPointerLikeOperatorStar ()));
305
+ EXPECT_TRUE (matches (
306
+ Decls,
307
+ " int target(HasGetAndValue<S> &NonConst) { return (*NonConst).i; }" ,
308
+ isPointerLikeOperatorStar ()));
309
+
217
310
EXPECT_TRUE (matches (
218
311
Decls,
219
312
" int target(const HasGetAndValue<S> &Const) { return (*Const).i; }" ,
220
313
isSmartPointerLikeOperatorStar ()));
314
+ EXPECT_TRUE (matches (
315
+ Decls,
316
+ " int target(const HasGetAndValue<S> &Const) { return (*Const).i; }" ,
317
+ isPointerLikeOperatorStar ()));
318
+
221
319
EXPECT_TRUE (matches (
222
320
Decls, " int target(HasGetAndValue<S> &NonConst) { return NonConst->i; }" ,
223
321
isSmartPointerLikeOperatorArrow ()));
322
+ EXPECT_TRUE (matches (
323
+ Decls, " int target(HasGetAndValue<S> &NonConst) { return NonConst->i; }" ,
324
+ isPointerLikeOperatorArrow ()));
325
+
224
326
EXPECT_TRUE (matches (
225
327
Decls, " int target(const HasGetAndValue<S> &Const) { return Const->i; }" ,
226
328
isSmartPointerLikeOperatorArrow ()));
329
+ EXPECT_TRUE (matches (
330
+ Decls, " int target(const HasGetAndValue<S> &Const) { return Const->i; }" ,
331
+ isPointerLikeOperatorArrow ()));
332
+
227
333
EXPECT_TRUE (matches (
228
334
Decls,
229
335
" int target(HasGetAndValue<S> &NonConst) { return NonConst.value().i; }" ,
0 commit comments