[cfe-commits] r89370 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/CodeGenCXX/new-with-default-arg.cpp
Fariborz Jahanian
fjahanian at apple.com
Thu Nov 19 10:39:40 PST 2009
Author: fjahanian
Date: Thu Nov 19 12:39:40 2009
New Revision: 89370
URL: http://llvm.org/viewvc/llvm-project?rev=89370&view=rev
Log:
Patch to implement new-operators with default args.
Fixes pr5547.
Added:
cfe/trunk/test/CodeGenCXX/new-with-default-arg.cpp
Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=89370&r1=89369&r2=89370&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Thu Nov 19 12:39:40 2009
@@ -326,7 +326,7 @@
QualType AllocType = GetTypeForDeclarator(D, /*Scope=*/0, &DInfo);
if (D.isInvalidType())
return ExprError();
-
+
return BuildCXXNew(StartLoc, UseGlobal,
PlacementLParen,
move(PlacementArgs),
@@ -394,7 +394,7 @@
FunctionDecl *OperatorDelete = 0;
Expr **PlaceArgs = (Expr**)PlacementArgs.get();
unsigned NumPlaceArgs = PlacementArgs.size();
-
+
if (!AllocType->isDependentType() &&
!Expr::hasAnyTypeDependentArguments(PlaceArgs, NumPlaceArgs) &&
FindAllocationFunctions(StartLoc,
@@ -402,7 +402,35 @@
UseGlobal, AllocType, ArraySize, PlaceArgs,
NumPlaceArgs, OperatorNew, OperatorDelete))
return ExprError();
-
+ llvm::SmallVector<Expr *, 4> AllPlaceArgs;
+ if (OperatorNew) {
+ // Add default arguments, if any.
+ const FunctionProtoType *Proto =
+ OperatorNew->getType()->getAs<FunctionProtoType>();
+ unsigned NumArgsInProto = Proto->getNumArgs();
+ for (unsigned i = 1; i != NumArgsInProto; i++) {
+ QualType ProtoArgType = Proto->getArgType(i);
+
+ Expr *Arg;
+ if (i <= NumPlaceArgs) {
+ AllPlaceArgs.push_back(PlaceArgs[i-1]);
+ continue;
+ }
+ ParmVarDecl *Param = OperatorNew->getParamDecl(i);
+
+ OwningExprResult ArgExpr =
+ BuildCXXDefaultArgExpr(StartLoc, OperatorNew, Param);
+ if (ArgExpr.isInvalid())
+ return ExprError();
+
+ Arg = ArgExpr.takeAs<Expr>();
+ AllPlaceArgs.push_back(Arg);
+ }
+ NumPlaceArgs = AllPlaceArgs.size();
+ if (NumPlaceArgs > 0)
+ PlaceArgs = &AllPlaceArgs[0];
+ }
+
bool Init = ConstructorLParen.isValid();
// --- Choosing a constructor ---
// C++ 5.3.4p15
Added: cfe/trunk/test/CodeGenCXX/new-with-default-arg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/new-with-default-arg.cpp?rev=89370&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/new-with-default-arg.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/new-with-default-arg.cpp Thu Nov 19 12:39:40 2009
@@ -0,0 +1,33 @@
+// RUN: clang-cc -emit-llvm -o - %s
+// pr5547
+
+struct A {
+ void* operator new(__typeof(sizeof(int)));
+ A();
+};
+
+A* x() {
+ return new A;
+}
+
+struct B {
+ void* operator new(__typeof(sizeof(int)), int = 1, int = 4);
+ B(float);
+};
+
+B* y() {
+ new (3,4) B(1);
+ return new(1) B(2);
+}
+
+struct C {
+ void* operator new(__typeof(sizeof(int)), int, int = 4);
+ C();
+};
+
+C* z() {
+ new (3,4) C;
+ return new(1) C;
+}
+
+
More information about the cfe-commits
mailing list