[clang] [Clang][C++26] Implement Pack Indexing (P2662R3). (PR #72644)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 9 10:21:20 PST 2024
================
@@ -4884,6 +4884,72 @@ class DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
Expr *E);
};
+class PackIndexingType final
+ : public Type,
+ public llvm::FoldingSetNode,
+ private llvm::TrailingObjects<PackIndexingType, QualType> {
+ friend TrailingObjects;
+
+ const ASTContext &Context;
+ QualType Pattern;
+ Expr *IndexExpr;
+
+ unsigned Size;
+ int Index = -1;
+
+protected:
+ friend class ASTContext; // ASTContext creates these.
+ PackIndexingType(const ASTContext &Context, QualType Canonical,
+ QualType Pattern, Expr *IndexExpr,
+ ArrayRef<QualType> Expansions = {}, int Index = -1);
+
+public:
+ Expr *getIndexExpr() const { return IndexExpr; }
+ QualType getPattern() const { return Pattern; }
+
+ bool isSugared() const { return hasSelectedType(); }
+
+ QualType desugar() const {
+ if (hasSelectedType())
+ return getSelectedType();
+ return QualType(this, 0);
+ }
+
+ QualType getSelectedType() const {
+ assert(hasSelectedType() && "Type is dependant");
+ return *(getExpansionsPtr() + Index);
+ }
+
+ bool hasSelectedType() const { return Index != -1 && !isDependentType(); }
----------------
erichkeane wrote:
Shouldn't JUST the second part of this be sufficient? I would think that as soon as we're not dependent, the index should be 'set', correct? Or am I misunderstanding?
https://github.com/llvm/llvm-project/pull/72644
More information about the cfe-commits
mailing list