[clang] [Clang][C++26] Implement Pack Indexing (P2662R3). (PR #72644)

Bevin Hansson via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 29 04:34:09 PST 2024


================
@@ -4934,6 +4934,73 @@ 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;
+
+protected:
+  friend class ASTContext; // ASTContext creates these.
+  PackIndexingType(const ASTContext &Context, QualType Canonical,
+                   QualType Pattern, Expr *IndexExpr,
+                   ArrayRef<QualType> Expansions = {});
+
+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);
+  }
----------------
bevin-hansson wrote:

Is this correct? Calling `getTypeInfo` on a PackIndexingType where hasSelectedType is false will cause it to infinitely recurse as it tries to desugar itself over and over again. This seems to happen if the type is broken, like the not_pack examples in cxx2c-pack-indexing.cpp.

Maybe the issue lies elsewhere, but something is strange with the error recovery for these types. Perhaps because `isDependentType` isn't true for them when they are broken?

https://github.com/llvm/llvm-project/pull/72644


More information about the cfe-commits mailing list