Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions clang/test/Sema/warn-lifetime-analysis-capture-by.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ void use() {
}
} // namespace this_is_captured

namespace temporary_capturing_object {
struct S {
void add(const int& x [[clang::lifetime_capture_by(this)]]);
};

void test() {
// We still give an warning even the capturing object is a temoprary.
// It is possible that the capturing object uses the captured object in its
// destructor.
S().add(1); // expected-warning {{object whose reference is captured}}
S{}.add(1); // expected-warning {{object whose reference is captured}}
}
} // namespace ignore_temporary_class_object

// ****************************************************************************
// Capture by Global and Unknown.
// ****************************************************************************
Expand Down