On Wed, Jun 5, 2013 at 4:43 AM, Timur Iskhodzhanov <span dir="ltr"><<a href="mailto:timurrrr@google.com" target="_blank">timurrrr@google.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
2013/6/5 Richard Smith <<a href="mailto:richard-llvm@metafoo.co.uk" target="_blank">richard-llvm@metafoo.co.uk</a>>:<br>
<div><div>> +/// Determine the declaration which an initialized entity ultimately refers to,<br>
> +/// for the purpose of lifetime-extending a temporary bound to a reference in<br>
> +/// the initialization of \p Entity.<br>
> +static const ValueDecl *<br>
> +getDeclForTemporaryLifetimeExtension(const InitializedEntity &Entity,<br>
> + const ValueDecl *FallbackDecl = 0) {<br>
> + // C++11 [class.temporary]p5:<br>
> + switch (Entity.getKind()) {<br>
> + case InitializedEntity::EK_Variable:<br>
> + // The temporary [...] persists for the lifetime of the reference<br>
> + return Entity.getDecl();<br>
> +<br>
> + case InitializedEntity::EK_Member:<br>
> + // For subobjects, we look at the complete object.<br>
> + if (Entity.getParent())<br>
> + return getDeclForTemporaryLifetimeExtension(*Entity.getParent(),<br>
> + Entity.getDecl());<br>
> +<br>
> + // except:<br>
> + // -- A temporary bound to a reference member in a constructor's<br>
> + // ctor-initializer persists until the constructor exits.<br>
> + return Entity.getDecl();<br>
> +<br>
> + case InitializedEntity::EK_Parameter:<br>
> + // -- A temporary bound to a reference parameter in a function call<br>
> + // persists until the completion of the full-expression containing<br>
> + // the call.<br>
> + case InitializedEntity::EK_Result:<br>
> + // -- The lifetime of a temporary bound to the returned value in a<br>
> + // function return statement is not extended; the temporary is<br>
> + // destroyed at the end of the full-expression in the return statement.<br>
> + case InitializedEntity::EK_New:<br>
> + // -- A temporary bound to a reference in a new-initializer persists<br>
> + // until the completion of the full-expression containing the<br>
> + // new-initializer.<br>
> + return 0;<br>
> +<br>
> + case InitializedEntity::EK_Temporary:<br>
> + case InitializedEntity::EK_CompoundLiteralInit:<br>
> + // We don't yet know the storage duration of the surrounding temporary.<br>
> + // Assume it's got full-expression duration for now, it will patch up our<br>
> + // storage duration if that's not correct.<br>
> + return 0;<br>
> +<br>
> + case InitializedEntity::EK_ArrayElement:<br>
> + // For subobjects, we look at the complete object.<br>
> + return getDeclForTemporaryLifetimeExtension(*Entity.getParent(),<br>
> + FallbackDecl);<br>
> +<br>
> + case InitializedEntity::EK_Base:<br>
> + case InitializedEntity::EK_Delegating:<br>
> + // We can reach this case for aggregate initialization in a constructor:<br>
> + // struct A { int &&r; };<br>
> + // struct B : A { B() : A{0} {} };<br>
> + // In this case, use the innermost field decl as the context.<br>
> + return FallbackDecl;<br>
> +<br>
> + case InitializedEntity::EK_BlockElement:<br>
> + case InitializedEntity::EK_LambdaCapture:<br>
> + case InitializedEntity::EK_Exception:<br>
> + case InitializedEntity::EK_VectorElement:<br>
> + case InitializedEntity::EK_ComplexElement:<br>
> + llvm_unreachable("should not materialize a temporary to initialize this");<br>
> + }<br>
> +}<br>
<br>
</div></div>gcc 4.6.3 gives the following warning on this code:<br>
In function ‘const clang::ValueDecl*<br>
getDeclForTemporaryLifetimeExtension(const clang::InitializedEntity&,<br>
const clang::ValueDecl*)’:<br>
tools/clang/lib/Sema/SemaInit.cpp:5196:1: warning: control reaches end<br>
of non-void function [-Wreturn-type]<br>
</blockquote></div><br><div>Thanks, looks like Benjamin Kramer fixed this already (thanks!).</div><div><br></div><div>Why do we still have this g++ warning enabled?</div>