diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-05-06 03:47:15 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-05-06 03:47:15 +0000 |
commit | 5b0a110410710c5e5b3a197edced3676c92b6e89 (patch) | |
tree | 8a3994ce841efa3aa2dfb291957cdd316053d3a1 /lib/Sema/TreeTransform.h | |
parent | f14f7e2753fb69cec95009f4f3b2e3eab14e4f10 (diff) | |
download | clang-5b0a110410710c5e5b3a197edced3676c92b6e89.tar.gz |
[c++20] Implement P1009R2: allow omitting the array bound in an array
new expression.
This was voted into C++20 as a defect report resolution, so we
retroactively apply it to all prior language modes (though it can never
actually be used before C++11 mode).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@360006 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/TreeTransform.h')
-rw-r--r-- | lib/Sema/TreeTransform.h | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index a8ea6b01d1..b1b2a911c2 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -2745,7 +2745,7 @@ public: SourceRange TypeIdParens, QualType AllocatedType, TypeSourceInfo *AllocatedTypeInfo, - Expr *ArraySize, + Optional<Expr *> ArraySize, SourceRange DirectInitRange, Expr *Initializer) { return getSema().BuildCXXNew(StartLoc, UseGlobal, @@ -10378,9 +10378,16 @@ TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { return ExprError(); // Transform the size of the array we're allocating (if any). - ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); - if (ArraySize.isInvalid()) - return ExprError(); + Optional<Expr *> ArraySize; + if (Optional<Expr *> OldArraySize = E->getArraySize()) { + ExprResult NewArraySize; + if (*OldArraySize) { + NewArraySize = getDerived().TransformExpr(*OldArraySize); + if (NewArraySize.isInvalid()) + return ExprError(); + } + ArraySize = NewArraySize.get(); + } // Transform the placement arguments (if any). bool ArgumentChanged = false; @@ -10417,7 +10424,7 @@ TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { if (!getDerived().AlwaysRebuild() && AllocTypeInfo == E->getAllocatedTypeSourceInfo() && - ArraySize.get() == E->getArraySize() && + ArraySize == E->getArraySize() && NewInit.get() == OldInit && OperatorNew == E->getOperatorNew() && OperatorDelete == E->getOperatorDelete() && @@ -10444,7 +10451,7 @@ TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { } QualType AllocType = AllocTypeInfo->getType(); - if (!ArraySize.get()) { + if (!ArraySize) { // If no array size was specified, but the new expression was // instantiated with an array type (e.g., "new T" where T is // instantiated with "int[4]"), extract the outer bound from the @@ -10472,7 +10479,7 @@ TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { E->getBeginLoc(), E->isGlobalNew(), /*FIXME:*/ E->getBeginLoc(), PlacementArgs, /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType, - AllocTypeInfo, ArraySize.get(), E->getDirectInitRange(), NewInit.get()); + AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get()); } template<typename Derived> |