-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Aggregate parens-init checks for dangling too aggressively #61567
Aggregate parens-init checks for dangling too aggressively #61567
Comments
@alanzhao1 @zygoloid I think this is more fallout from #61145 please confirm |
Yeah, I suspect the problem in this case is that we're incorrectly reusing the rules that we use in a constructor's mem-initializer-list (in which context this kind of initialization is ill-formed) here. We probably need a new kind of |
@llvm/issue-subscribers-c-20 |
Candidate patch: https://reviews.llvm.org/D148274 |
@shafik any thoughts on backporting this into 16.0.x? |
Reopening for backporting per discussion in https://reviews.llvm.org/D150122 I'll wait for #62266 to be backported before working on this fix as otherwise there'll be a merge issue. |
…gate initialization Before this patch, initialized class members would have the LifetimeKind LK_MemInitializer, which does not allow for binding a temporary to a reference. Binding to a temporary however is allowed in parenthesized aggregate initialization, even if it leads to a dangling reference. To fix this, we create a new EntityKind, EK_ParenAggInitMember, which has LifetimeKind LK_FullExpression. This patch does *not* attempt to diagnose dangling references as a result of using this feature. This patch also refactors TryOrBuildParenListInitialization(...) to accomodate creating different InitializedEntity objects. Fixes llvm#61567 [0]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0960r3.html Reviewed By: shafik Differential Revision: https://reviews.llvm.org/D148274
/branch alanzhao1/llvm-project/backport-61567 |
/pull-request llvm/llvm-project-release-prs#446 |
…gate initialization Before this patch, initialized class members would have the LifetimeKind LK_MemInitializer, which does not allow for binding a temporary to a reference. Binding to a temporary however is allowed in parenthesized aggregate initialization, even if it leads to a dangling reference. To fix this, we create a new EntityKind, EK_ParenAggInitMember, which has LifetimeKind LK_FullExpression. This patch does *not* attempt to diagnose dangling references as a result of using this feature. This patch also refactors TryOrBuildParenListInitialization(...) to accomodate creating different InitializedEntity objects. Fixes #61567 [0]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0960r3.html Reviewed By: shafik Differential Revision: https://reviews.llvm.org/D148274
…gate initialization Before this patch, initialized class members would have the LifetimeKind LK_MemInitializer, which does not allow for binding a temporary to a reference. Binding to a temporary however is allowed in parenthesized aggregate initialization, even if it leads to a dangling reference. To fix this, we create a new EntityKind, EK_ParenAggInitMember, which has LifetimeKind LK_FullExpression. This patch does *not* attempt to diagnose dangling references as a result of using this feature. This patch also refactors TryOrBuildParenListInitialization(...) to accomodate creating different InitializedEntity objects. Fixes llvm#61567 [0]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0960r3.html Reviewed By: shafik Differential Revision: https://reviews.llvm.org/D148274
Clang rejects the well-formed but dangling cases from http://eel.is/c++draft/dcl.init.general#example-3:
Now, these particular examples may well have justified a warning, but Clang also rejects
in which both the temporary and the aggregate live to the end of the full-expression. It also warns on
even though
i
outlives the aggregate.This will affect uses of C++23
std::ranges::elements_of
, which is an aggregate with a reference member that is intended to be used exactly like this.The text was updated successfully, but these errors were encountered: