-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Support use of clang::lifetime_capture_by in constructors #117680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This case is already supported. The warning is not shown because this warning is disabled by default, see https://godbolt.org/z/rqKhW9qEW. |
Hmm. I expected it to not work. struct T{
T(const int& t [[clang::lifetime_capture_by(this)]]);
};
int foo(const T& t);
void foo() {
auto x = foo(T(1)); // Error. False positive.
} |
I see. I think this is a case (I hit it in #117690 as well) where both the container and temporary object are destroyed at the end of the full expression, and the Do we want to diagnose on the following case? I think probably not (in order to reduce noise)
|
struct T{
T(const int& t [[clang::lifetime_capture_by(this)]]);
};
int foo(const T& t);
int bar(const T& t [[clang::lifetimebound]]);
void foo() {
auto x = foo(T(1)); // Should be ok.
auto y = bar(T(1)); // error is expected.
} I would lean towards treating this as we treat lifetimebound for ctors here: llvm-project/clang/lib/Sema/CheckExprLifetime.cpp Lines 624 to 630 in 4a7b56e
And not trigger checkCaptureByLifetime for constructors
|
https://godbolt.org/z/KqM3znMhT
The text was updated successfully, but these errors were encountered: