================
@@ -29,13 +45,33 @@ namespace capture_string {
struct X {} x;
void captureString(const std::string &s [[clang::lifetime_capture_by(x)]], X
&x);
void captureRValString(std::string &&s [[clang::lifetime_capture_by(x)]], X
&x);
+void noCaptureString(std::string s [[clang::lifetime_capture_by(x)]], X &x);
+
+void temporary_string_capture() {
+ captureString(std::string(), x); // expected-warning {{object whose
reference is captured by 'x' will be destroyed at the end of the
full-expression}} \
+ // cfg-warning {{temporary object does not
live long enough}} \
+ // cfg-note {{destroyed here}}
+ (void)x; // cfg-note {{later used here}}
+ captureRValString(std::string(), x); // expected-warning {{object whose
reference is captured by 'x' will be destroyed at the end of the
full-expression}} \
+ // cfg-warning {{temporary object does
not live long enough}} \
+ // cfg-note {{destroyed here}}
+ (void)x; // cfg-note {{later used here}}
+}
-void use() {
- std::string local_string;
- captureString(std::string(), x); // expected-warning {{object whose
reference is captured by 'x' will be destroyed at the end of the
full-expression}}
- captureString(local_string, x);
- captureRValString(std::move(local_string), x);
- captureRValString(std::string(), x); // expected-warning {{object whose
reference is captured by 'x' will be destroyed at the end of the
full-expression}}
+void local_string_capture() {
+ {
+ std::string local_string1, local_string2;
+ captureString(local_string1, x); // cfg-warning {{local
variable 'local_string1' does not live long enough}}
+ captureRValString(std::move(local_string2), x); // cfg-warning {{local
variable 'local_string2' does not live long enough}} \
+ // cfg-note {{result of call to
'move<std::basic_string<char> &>' aliases the storage of local variable
'local_string2'}}
----------------
usx95 wrote:
nit: match the indent with the corresponding warning above for the same line
and not the other notes.
https://github.com/llvm/llvm-project/pull/204361
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits