[cfe-commits] r89370 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/CodeGenCXX/new-with-default-arg.cpp

Douglas Gregor dgregor at apple.com
Fri Nov 20 15:19:12 PST 2009


On Nov 19, 2009, at 10:39 AM, Fariborz Jahanian wrote:

> 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];
> +  }
> +

We now have this code in three separate places:  
CompleteConstructorCall, ConvertArgumentsForCall, and here. Is there  
any way to unify this code?

Also: I think this code will have to deal with conversions for  
arguments passed through "..." (or will have to pick up those  
conversions through the aforementioned unification).

   - Doug



More information about the cfe-commits mailing list