<div dir="ltr">On Tue, Nov 19, 2013 at 10:18 PM, Karthik Bhat <span dir="ltr"><<a href="mailto:kv.bhat@samsung.com" target="_blank">kv.bhat@samsung.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi rsmith,<br>
<br>
Hi All,Richard,<br>
I would like to get few inputs regarding the issue mentioned below.<br>
Clang fails to compile gcc test case constexpr-initlist2.C with c++11 (<a href="http://searchcode.com/codesearch/view/8022759" target="_blank">http://searchcode.com/codesearch/view/8022759</a>)<br>
<br>
lvalue-to-rvalue conversion seems to be failing.<br>
<br>
As per standard [expr.const] -<br>
an lvalue-to-rvalue conversion [is not allowed unless it applies to]<br>
[....]<br>
— a non-volatile glvalue that refers to a non-volatile object defined with constexpr, or that refers<br>
to a non-mutable sub-object of such an object<br></blockquote><div><br></div><div>This does not apply to your testcase. The testcase creates, and tries to read from, an array temporary (which is not a non-volatile object defined with 'constexpr' nor a subobject thereof).</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
[....]<br>
<br>
Hence as per standard it seems clang should be able to compile the above code(constexpr-initlist2.C)<br>
<br>
The problem seems we are not handling this case on ExprConstant findCompleteObject function. Added a patch to fix the same.<br>
I would like to get inputs from community if this is the right approach?<br>
Will update/add the test case in case the approach is correct.<br>
<br>
Thanks<br>
Karthik Bhat<br>
<br>
<a href="http://llvm-reviews.chandlerc.com/D2226" target="_blank">http://llvm-reviews.chandlerc.com/D2226</a><br>
<br>
Files:<br>
lib/AST/ExprConstant.cpp<br>
<br>
Index: lib/AST/ExprConstant.cpp<br>
===================================================================<br>
--- lib/AST/ExprConstant.cpp<br>
+++ lib/AST/ExprConstant.cpp<br>
@@ -2503,6 +2503,9 @@<br>
// [...]<br>
// - a [...] glvalue of literal type that refers to a non-volatile<br>
// object whose lifetime began within the evaluation of e.<br>
+ // [...]<br>
+ // - a [...] glvalue that refers to a non-volatile object<br>
+ // defined with constexpr<br>
//<br>
// C++11 misses the 'began within the evaluation of e' check and<br>
// instead allows all temporaries, including things like:<br></blockquote><div><br></div><div>This text explains what we're doing here, and why.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
@@ -2512,8 +2515,10 @@<br>
// Therefore we use the C++1y rules in C++11 too.<br>
const ValueDecl *VD = Info.EvaluatingDecl.dyn_cast<const ValueDecl*>();<br>
const ValueDecl *ED = MTE->getExtendingDecl();<br>
+ const VarDecl* VarD = dyn_cast<const VarDecl>(ED);<br>
if (!(BaseType.isConstQualified() &&<br>
BaseType->isIntegralOrEnumerationType()) &&<br>
+ !(VarD && VarD->isConstexpr()) &&<br>
!(VD && VD->getCanonicalDecl() == ED->getCanonicalDecl())) {<br>
Info.Diag(E, diag::note_constexpr_access_static_temporary, 1) << AK;<br>
Info.Note(MTE->getExprLoc(), diag::note_constexpr_temporary_here);<br>
</blockquote></div><br></div><div class="gmail_extra">That change is not correct; it allows this:</div><div class="gmail_extra"><br></div><div class="gmail_extra"> constexpr int &&r = 0;</div><div class="gmail_extra">
++r;</div><div class="gmail_extra"> constexpr int n = r; // would have value 0 with your patch</div></div>