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 | b9fb121a62de69686dc193d32cba680a1a645277 (patch) | |
tree | 5ae91995df8eb4264fd2fa71fe3ef48a8e95d160 /clang/lib/AST/ExprCXX.cpp | |
parent | 9dd6537b3acf98c942cdb020c6ea26d9af309eb3 (diff) | |
download | bcm5719-llvm-b9fb121a62de69686dc193d32cba680a1a645277.tar.gz bcm5719-llvm-b9fb121a62de69686dc193d32cba680a1a645277.zip |
[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).
llvm-svn: 360006
Diffstat (limited to 'clang/lib/AST/ExprCXX.cpp')
-rw-r--r-- | clang/lib/AST/ExprCXX.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp index b1ce1674014..bbf7e044aae 100644 --- a/clang/lib/AST/ExprCXX.cpp +++ b/clang/lib/AST/ExprCXX.cpp @@ -97,7 +97,8 @@ CXXNewExpr::CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize, ArrayRef<Expr *> PlacementArgs, SourceRange TypeIdParens, - Expr *ArraySize, InitializationStyle InitializationStyle, + Optional<Expr *> ArraySize, + InitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange) @@ -112,7 +113,7 @@ CXXNewExpr::CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew, "Only NoInit can have no initializer!"); CXXNewExprBits.IsGlobalNew = IsGlobalNew; - CXXNewExprBits.IsArray = ArraySize != nullptr; + CXXNewExprBits.IsArray = ArraySize.hasValue(); CXXNewExprBits.ShouldPassAlignment = ShouldPassAlignment; CXXNewExprBits.UsualArrayDeleteWantsSize = UsualArrayDeleteWantsSize; CXXNewExprBits.StoredInitializationStyle = @@ -122,12 +123,14 @@ CXXNewExpr::CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew, CXXNewExprBits.NumPlacementArgs = PlacementArgs.size(); if (ArraySize) { - if (ArraySize->isInstantiationDependent()) - ExprBits.InstantiationDependent = true; - if (ArraySize->containsUnexpandedParameterPack()) - ExprBits.ContainsUnexpandedParameterPack = true; + if (Expr *SizeExpr = *ArraySize) { + if (SizeExpr->isInstantiationDependent()) + ExprBits.InstantiationDependent = true; + if (SizeExpr->containsUnexpandedParameterPack()) + ExprBits.ContainsUnexpandedParameterPack = true; + } - getTrailingObjects<Stmt *>()[arraySizeOffset()] = ArraySize; + getTrailingObjects<Stmt *>()[arraySizeOffset()] = *ArraySize; } if (Initializer) { @@ -179,11 +182,11 @@ CXXNewExpr::Create(const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize, ArrayRef<Expr *> PlacementArgs, SourceRange TypeIdParens, - Expr *ArraySize, InitializationStyle InitializationStyle, - Expr *Initializer, QualType Ty, - TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, - SourceRange DirectInitRange) { - bool IsArray = ArraySize != nullptr; + Optional<Expr *> ArraySize, + InitializationStyle InitializationStyle, Expr *Initializer, + QualType Ty, TypeSourceInfo *AllocatedTypeInfo, + SourceRange Range, SourceRange DirectInitRange) { + bool IsArray = ArraySize.hasValue(); bool HasInit = Initializer != nullptr; unsigned NumPlacementArgs = PlacementArgs.size(); bool IsParenTypeId = TypeIdParens.isValid(); |