[cfe-commits] r140459 - in /cfe/trunk: lib/AST/ExprConstant.cpp lib/CodeGen/CGExprScalar.cpp lib/Sema/SemaInit.cpp test/CodeGenCXX/cxx0x-initializer-scalars.cpp

Douglas Gregor dgregor at apple.com
Mon Sep 26 08:07:40 PDT 2011


On Sep 24, 2011, at 10:48 AM, Sebastian Redl wrote:

> Author: cornedbee
> Date: Sat Sep 24 12:48:14 2011
> New Revision: 140459
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=140459&view=rev
> Log:
> Treat list-initialization of scalars as a first-class citizen in C++11.
> Allow empty initializer lists for scalars, which mean value-initialization.
> Constant evaluation for single-element and empty initializer lists for scalars.
> Codegen for empty initializer lists for scalars.
> Test case comes in next commit.
> 
> Added:
>    cfe/trunk/test/CodeGenCXX/cxx0x-initializer-scalars.cpp
> Modified:
>    cfe/trunk/lib/AST/ExprConstant.cpp
>    cfe/trunk/lib/CodeGen/CGExprScalar.cpp
>    cfe/trunk/lib/Sema/SemaInit.cpp
> 
> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=140459&r1=140458&r2=140459&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
> +++ cfe/trunk/lib/AST/ExprConstant.cpp Sat Sep 24 12:48:14 2011
> @@ -484,6 +484,13 @@
>       return Visit(E->getSubExpr());
>     }
>   }
> +
> +  bool VisitInitListExpr(const InitListExpr *E) {
> +    if (Info.Ctx.getLangOptions().CPlusPlus0x && E->getNumInits() == 1)
> +      return Visit(E->getInit(0));
> +    return Error(E);
> +  }
> +
>   // FIXME: Missing: __real__, __imag__
> 
> };
> @@ -1079,7 +1086,9 @@
> 
>   bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E);
>   bool VisitSizeOfPackExpr(const SizeOfPackExpr *E);
> -    
> +
> +  bool VisitInitListExpr(const InitListExpr *E);
> +
> private:
>   CharUnits GetAlignOfExpr(const Expr *E);
>   CharUnits GetAlignOfType(QualType T);
> @@ -1932,6 +1941,17 @@
>   return Success(E->getValue(), E);
> }
> 
> +bool IntExprEvaluator::VisitInitListExpr(const InitListExpr *E) {
> +  if (!Info.Ctx.getLangOptions().CPlusPlus0x)
> +    return Error(E);
> +
> +  if (E->getNumInits() == 0)
> +    return Success(0, E);
> +
> +  assert(E->getNumInits() == 1 && "Excess initializers for integer in C++11.");
> +  return Visit(E->getInit(0));
> +}

I'm flip-flopping a little on whether I would prefer:

	if (!Info.Ctx.getLangOptions().CPlusPlus0x || E->getNumInits() > 1)

so we don't have the assertion. It seems overly picky to assert on this kind of thing, when it is allowed in some dialects. Perhaps I'm just being paranoid.

> +bool FloatExprEvaluator::VisitInitListExpr(const InitListExpr *E) {
> +  if (!Info.Ctx.getLangOptions().CPlusPlus0x)
> +    return Error(E);
> +
> +  if (E->getNumInits() == 0) {
> +    Result = APFloat::getZero(Info.Ctx.getFloatTypeSemantics(E->getType()));
> +    return true;
> +  }
> +
> +  assert(E->getNumInits() == 1 && "Excess initializers for integer in C++11.");
> +  return Visit(E->getInit(0));
> +}

Same flip-flopping comment here :)

	- Doug




More information about the cfe-commits mailing list