-
Notifications
You must be signed in to change notification settings - Fork 12.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
[Clang][P1061] Add stuctured binding packs #121417
Changes from 9 commits
3c81c5b
116aff1
66ff7c6
5720bd3
ffefb67
685f947
d957783
91ca5b4
abab5cf
80acb71
360708d
ea249ac
dda9d89
0b83b99
d496c54
d064095
97257d7
39ab76e
765db8a
8cf8205
6d49a3d
5c351d7
5302830
e497a0c
5751d2f
36f8029
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5321,6 +5321,59 @@ class BuiltinBitCastExpr final | |
} | ||
}; | ||
|
||
// Represents an unexpanded pack where the list of expressions are | ||
// known. These are used when structured bindings introduce a pack. | ||
class ResolvedUnexpandedPackExpr final | ||
cor3ntin marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+5324
to
+5326
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be doing the same job as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I definitely think they could be generalized which is what I had in mind with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we try to address that? |
||
: public Expr, | ||
private llvm::TrailingObjects<ResolvedUnexpandedPackExpr, Expr *> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we store There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably. That would simplify the DeclRefExpr stuff and a few other things. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is what I think: using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I am content to leave it as is, but storing Decls instead of Exprs does have the benefit of delaying building the DeclRefExprs until expansion which creates less garbage and would simplify There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
A use case would be unpacking a tuple for example (or data member pack but in that case maybe we want to store decl for that too) Either way, I don't think we should predicament the design on future evolution. If we need to change it later, we can |
||
friend class ASTStmtReader; | ||
friend class ASTStmtWriter; | ||
friend TrailingObjects; | ||
|
||
SourceLocation BeginLoc; | ||
unsigned NumExprs; | ||
|
||
ResolvedUnexpandedPackExpr(SourceLocation BL, QualType QT, unsigned NumExprs); | ||
|
||
public: | ||
static ResolvedUnexpandedPackExpr *CreateDeserialized(ASTContext &C, | ||
unsigned NumExprs); | ||
static ResolvedUnexpandedPackExpr * | ||
Create(ASTContext &C, SourceLocation BeginLoc, QualType T, unsigned NumExprs); | ||
static ResolvedUnexpandedPackExpr *Create(ASTContext &C, | ||
SourceLocation BeginLoc, QualType T, | ||
llvm::ArrayRef<Expr *> Exprs); | ||
|
||
unsigned getNumExprs() const { return NumExprs; } | ||
|
||
llvm::MutableArrayRef<Expr *> getExprs() { | ||
return {getTrailingObjects<Expr *>(), NumExprs}; | ||
} | ||
|
||
llvm::ArrayRef<Expr *> getExprs() const { | ||
return {getTrailingObjects<Expr *>(), NumExprs}; | ||
} | ||
|
||
Expr *getExpansion(unsigned Idx) { return getExprs()[Idx]; } | ||
Expr *getExpansion(unsigned Idx) const { return getExprs()[Idx]; } | ||
|
||
// Iterators | ||
child_range children() { | ||
return child_range((Stmt **)getTrailingObjects<Expr *>(), | ||
(Stmt **)getTrailingObjects<Expr *>() + getNumExprs()); | ||
} | ||
|
||
SourceLocation getBeginLoc() const LLVM_READONLY { return BeginLoc; } | ||
SourceLocation getEndLoc() const LLVM_READONLY { return BeginLoc; } | ||
|
||
// Returns the resolved pack of a decl or nullptr | ||
static ResolvedUnexpandedPackExpr *getFromDecl(Decl *); | ||
|
||
static bool classof(const Stmt *T) { | ||
return T->getStmtClass() == ResolvedUnexpandedPackExprClass; | ||
} | ||
}; | ||
|
||
} // namespace clang | ||
|
||
#endif // LLVM_CLANG_AST_EXPRCXX_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1099,6 +1099,13 @@ def err_lambda_capture_misplaced_ellipsis : Error< | |
"the name of the capture">; | ||
def err_lambda_capture_multiple_ellipses : Error< | ||
"multiple ellipses in pack capture">; | ||
def err_binding_multiple_ellipses : Error< | ||
"multiple ellipses in structured binding declaration">; | ||
def note_previous_ellipsis : Note< | ||
"previous ellipsis specified here">; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems a little strange to talk about ellipses rather than packs here. Maybe "multiple binding packs in [...]" instead? |
||
def ext_cxx_binding_pack : ExtWarn< | ||
cor3ntin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"structured binding pack is incompatible with C++ standards before C++2c">, | ||
InGroup<CXX26>; | ||
def err_capture_default_first : Error< | ||
"capture default must be first">; | ||
def ext_decl_attrs_on_lambda : ExtWarn< | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get the comment to move as well? Or at least an updated one?