@@ -23,6 +23,7 @@ void noCaptureStringView(std::string_view sv, X &x);
23
23
void captureString (const std::string &s [[clang::lifetime_capture_by(x)]], X &x);
24
24
void captureRValString (std::string &&s [[clang::lifetime_capture_by(x)]], X &x);
25
25
26
+ // Return reference to the argument through lifetimebound.
26
27
const std::string& getLB (const std::string &s [[clang::lifetimebound]]);
27
28
const std::string& getLB (std::string_view sv [[clang::lifetimebound]]);
28
29
const std::string* getPointerLB (const std::string &s [[clang::lifetimebound]]);
@@ -167,45 +168,45 @@ MyStringViewNotPointer getMySVNotP();
167
168
168
169
void container_of_pointers () {
169
170
std::string local;
170
- MyVector<std::string> vs ;
171
- vs .push_back (std::string ()); // Ok.
171
+ MyVector<std::string> vector_of_string ;
172
+ vector_of_string .push_back (std::string ()); // Ok.
172
173
173
- MyVector<std::string_view> vsv ;
174
- vsv .push_back (std::string ()); // expected-warning {{object whose reference is captured by 'vsv '}}
175
- vsv .push_back (substr (std::string ())); // expected-warning {{object whose reference is captured by 'vsv' }}
174
+ MyVector<std::string_view> vector_of_view ;
175
+ vector_of_view .push_back (std::string ()); // expected-warning {{object whose reference is captured by 'vector_of_view '}}
176
+ vector_of_view .push_back (substr (std::string ())); // expected-warning {{captured}}
176
177
177
- MyVector<const std::string*> vp ;
178
- vp .push_back (getPointerLB (std::string ())); // expected-warning {{object whose reference is captured by 'vp' }}
179
- vp .push_back (getPointerLB (*getPointerLB (std::string ()))); // expected-warning {{object whose reference is captured by 'vp' }}
180
- vp .push_back (getPointerLB (local));
181
- vp .push_back (getPointerNoLB (std::string ()));
178
+ MyVector<const std::string*> vector_of_pointer ;
179
+ vector_of_pointer .push_back (getPointerLB (std::string ())); // expected-warning {{captured}}
180
+ vector_of_pointer .push_back (getPointerLB (*getPointerLB (std::string ()))); // expected-warning {{captured}}
181
+ vector_of_pointer .push_back (getPointerLB (local));
182
+ vector_of_pointer .push_back (getPointerNoLB (std::string ()));
182
183
183
184
// User-defined [[gsl::Pointer]]
184
- vsv .push_back (getMySV ());
185
- vsv .push_back (getMySVNotP ());
185
+ vector_of_view .push_back (getMySV ());
186
+ vector_of_view .push_back (getMySVNotP ());
186
187
187
188
// Vector of user defined gsl::Pointer.
188
- MyVector<MyStringView> vmysv ;
189
- vmysv .push_back (getMySV ());
190
- vmysv .push_back (MyStringView{});
191
- vmysv .push_back (std::string_view{});
192
- vmysv .push_back (std::string{}); // expected-warning {{object whose reference is captured by 'vmysv '}}
193
- vmysv .push_back (substr (std::string{})); // expected-warning {{object whose reference is captured by 'vmysv' }}
194
- vmysv .push_back (getLB (substr (std::string{}))); // expected-warning {{object whose reference is captured by 'vmysv' }}
195
- vmysv .push_back (strcopy (getLB (substr (std::string{}))));
189
+ MyVector<MyStringView> vector_of_my_view ;
190
+ vector_of_my_view .push_back (getMySV ());
191
+ vector_of_my_view .push_back (MyStringView{});
192
+ vector_of_my_view .push_back (std::string_view{});
193
+ vector_of_my_view .push_back (std::string{}); // expected-warning {{object whose reference is captured by 'vector_of_my_view '}}
194
+ vector_of_my_view .push_back (substr (std::string{})); // expected-warning {{captured}}
195
+ vector_of_my_view .push_back (getLB (substr (std::string{}))); // expected-warning {{captured}}
196
+ vector_of_my_view .push_back (strcopy (getLB (substr (std::string{}))));
196
197
197
198
// With std::optional container.
198
- std::optional<std::string_view> optionalSV ;
199
- vsv .push_back (optionalSV .value ());
200
- vsv .push_back (getOptionalS ().value ()); // expected-warning {{object whose reference is captured by 'vsv' }}
199
+ std::optional<std::string_view> optional_of_view ;
200
+ vector_of_view .push_back (optional_of_view .value ());
201
+ vector_of_view .push_back (getOptionalS ().value ()); // expected-warning {{captured}}
201
202
202
203
// FIXME: Following 2 cases are false positives:
203
- vsv .push_back (getOptionalSV ().value ()); // expected-warning {{object whose reference }}
204
- vsv .push_back (getOptionalMySV ().value ()); // expected-warning {{object whose reference }}
204
+ vector_of_view .push_back (getOptionalSV ().value ()); // expected-warning {{captured }}
205
+ vector_of_view .push_back (getOptionalMySV ().value ()); // expected-warning {{captured }}
205
206
206
207
// (maybe) FIXME: We may choose to diagnose the following case.
207
208
// This happens because 'MyStringViewNotPointer' is not marked as a [[gsl::Pointer]] but is derived from one.
208
- vsv .push_back (getOptionalMySVNotP ().value ()); // expected-warning {{object whose reference is captured by 'vsv' }}
209
+ vector_of_view .push_back (getOptionalMySVNotP ().value ()); // expected-warning {{captured}}
209
210
}
210
211
211
212
namespace temporary_views {
0 commit comments