================
@@ -30,20 +46,33 @@ 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 use() {
- std::string local_string;
+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}}
- captureString(local_string, x);
- captureRValString(std::move(local_string), x);
+ // cfg-warning@-1 {{temporary object does
not live long enough}}
+ // cfg-note@-2 {{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@-1 {{temporary object
does not live long enough}}
+ // cfg-note@-2 {{destroyed here}}
+ (void)x; // cfg-note {{later used here}}
+}
+
+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@-1 {{result of call to
'move<std::basic_string<char> &>' aliases the storage of local variable
'local_string2'}}
+ } // cfg-note 2 {{destroyed here}}
+ (void)x; // cfg-note 2 {{later used here}}
}
----------------
kashika0112 wrote:
Added a test case with safe captures and no warnings.
https://github.com/llvm/llvm-project/pull/204361
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits