r203025 - PR19010: Make sure we initialize (empty) indirect base class subobjects when

Richard Smith richard at metafoo.co.uk
Wed Mar 5 15:41:45 PST 2014


On Wed, Mar 5, 2014 at 3:32 PM, Richard Smith <richard-llvm at metafoo.co.uk>wrote:

> Author: rsmith
> Date: Wed Mar  5 17:32:50 2014
> New Revision: 203025
>
> URL: http://llvm.org/viewvc/llvm-project?rev=203025&view=rev
> Log:
> PR19010: Make sure we initialize (empty) indirect base class subobjects
> when
> evaluating trivial default initialization of a literal class type.
>

I forgot to add: patch by Stephan Tolksdorf!


> Modified:
>     cfe/trunk/lib/AST/ExprConstant.cpp
>     cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
>
> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=203025&r1=203024&r2=203025&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
> +++ cfe/trunk/lib/AST/ExprConstant.cpp Wed Mar  5 17:32:50 2014
> @@ -5117,16 +5117,15 @@ bool RecordExprEvaluator::VisitCXXConstr
>      if (!Result.isUninit())
>        return true;
>
> -    if (ZeroInit)
> -      return ZeroInitialization(E);
> -
> -    const CXXRecordDecl *RD = FD->getParent();
> -    if (RD->isUnion())
> -      Result = APValue((FieldDecl*)0);
> -    else
> -      Result = APValue(APValue::UninitStruct(), RD->getNumBases(),
> -                       std::distance(RD->field_begin(), RD->field_end()));
> -    return true;
> +    // We can get here in two different ways:
> +    //  1) We're performing value-initialization, and should
> zero-initialize
> +    //     the object, or
> +    //  2) We're performing default-initialization of an object with a
> trivial
> +    //     constexpr default constructor, in which case we should start
> the
> +    //     lifetimes of all the base subobjects (there can be no data
> member
> +    //     subobjects in this case) per [basic.life]p1.
> +    // Either way, ZeroInitialization is appropriate.
> +    return ZeroInitialization(E);
>    }
>
>    const FunctionDecl *Definition = 0;
> @@ -5606,19 +5605,9 @@ bool ArrayExprEvaluator::VisitCXXConstru
>      if (HadZeroInit)
>        return true;
>
> -    if (ZeroInit) {
> -      ImplicitValueInitExpr VIE(Type);
> -      return EvaluateInPlace(*Value, Info, Subobject, &VIE);
> -    }
> -
> -    const CXXRecordDecl *RD = FD->getParent();
> -    if (RD->isUnion())
> -      *Value = APValue((FieldDecl*)0);
> -    else
> -      *Value =
> -          APValue(APValue::UninitStruct(), RD->getNumBases(),
> -                  std::distance(RD->field_begin(), RD->field_end()));
> -    return true;
> +    // See RecordExprEvaluator::VisitCXXConstructExpr for explanation.
> +    ImplicitValueInitExpr VIE(Type);
> +    return EvaluateInPlace(*Value, Info, Subobject, &VIE);
>    }
>
>    const FunctionDecl *Definition = 0;
>
> Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=203025&r1=203024&r2=203025&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
> +++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Wed Mar  5
> 17:32:50 2014
> @@ -1863,3 +1863,13 @@ namespace BuiltinStrlen {
>    constexpr char d[] = { 'f', 'o', 'o' }; // no nul terminator.
>    constexpr int bad = __builtin_strlen(d); // expected-error {{constant
> expression}} expected-note {{one-past-the-end}}
>  }
> +
> +namespace PR19010 {
> +  struct Empty {};
> +  struct Empty2 : Empty {};
> +  struct Test : Empty2 {
> +    constexpr Test() {}
> +    Empty2 array[2];
> +  };
> +  void test() { constexpr Test t; }
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140305/30e81e79/attachment.html>


More information about the cfe-commits mailing list