<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Mar 5, 2014 at 3:32 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard-llvm@metafoo.co.uk" target="_blank">richard-llvm@metafoo.co.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: rsmith<br>
Date: Wed Mar 5 17:32:50 2014<br>
New Revision: 203025<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=203025&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=203025&view=rev</a><br>
Log:<br>
PR19010: Make sure we initialize (empty) indirect base class subobjects when<br>
evaluating trivial default initialization of a literal class type.<br></blockquote><div><br></div><div>I forgot to add: patch by Stephan Tolksdorf!</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Modified:<br>
cfe/trunk/lib/AST/ExprConstant.cpp<br>
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp<br>
<br>
Modified: cfe/trunk/lib/AST/ExprConstant.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=203025&r1=203024&r2=203025&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=203025&r1=203024&r2=203025&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)<br>
+++ cfe/trunk/lib/AST/ExprConstant.cpp Wed Mar 5 17:32:50 2014<br>
@@ -5117,16 +5117,15 @@ bool RecordExprEvaluator::VisitCXXConstr<br>
if (!Result.isUninit())<br>
return true;<br>
<br>
- if (ZeroInit)<br>
- return ZeroInitialization(E);<br>
-<br>
- const CXXRecordDecl *RD = FD->getParent();<br>
- if (RD->isUnion())<br>
- Result = APValue((FieldDecl*)0);<br>
- else<br>
- Result = APValue(APValue::UninitStruct(), RD->getNumBases(),<br>
- std::distance(RD->field_begin(), RD->field_end()));<br>
- return true;<br>
+ // We can get here in two different ways:<br>
+ // 1) We're performing value-initialization, and should zero-initialize<br>
+ // the object, or<br>
+ // 2) We're performing default-initialization of an object with a trivial<br>
+ // constexpr default constructor, in which case we should start the<br>
+ // lifetimes of all the base subobjects (there can be no data member<br>
+ // subobjects in this case) per [basic.life]p1.<br>
+ // Either way, ZeroInitialization is appropriate.<br>
+ return ZeroInitialization(E);<br>
}<br>
<br>
const FunctionDecl *Definition = 0;<br>
@@ -5606,19 +5605,9 @@ bool ArrayExprEvaluator::VisitCXXConstru<br>
if (HadZeroInit)<br>
return true;<br>
<br>
- if (ZeroInit) {<br>
- ImplicitValueInitExpr VIE(Type);<br>
- return EvaluateInPlace(*Value, Info, Subobject, &VIE);<br>
- }<br>
-<br>
- const CXXRecordDecl *RD = FD->getParent();<br>
- if (RD->isUnion())<br>
- *Value = APValue((FieldDecl*)0);<br>
- else<br>
- *Value =<br>
- APValue(APValue::UninitStruct(), RD->getNumBases(),<br>
- std::distance(RD->field_begin(), RD->field_end()));<br>
- return true;<br>
+ // See RecordExprEvaluator::VisitCXXConstructExpr for explanation.<br>
+ ImplicitValueInitExpr VIE(Type);<br>
+ return EvaluateInPlace(*Value, Info, Subobject, &VIE);<br>
}<br>
<br>
const FunctionDecl *Definition = 0;<br>
<br>
Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=203025&r1=203024&r2=203025&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=203025&r1=203024&r2=203025&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Wed Mar 5 17:32:50 2014<br>
@@ -1863,3 +1863,13 @@ namespace BuiltinStrlen {<br>
constexpr char d[] = { 'f', 'o', 'o' }; // no nul terminator.<br>
constexpr int bad = __builtin_strlen(d); // expected-error {{constant expression}} expected-note {{one-past-the-end}}<br>
}<br>
+<br>
+namespace PR19010 {<br>
+ struct Empty {};<br>
+ struct Empty2 : Empty {};<br>
+ struct Test : Empty2 {<br>
+ constexpr Test() {}<br>
+ Empty2 array[2];<br>
+ };<br>
+ void test() { constexpr Test t; }<br>
+}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>