<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 7, 2015 at 6:11 PM, Nikola Smiljanic <span dir="ltr"><<a href="mailto:popizdeh@gmail.com" target="_blank">popizdeh@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div dir="ltr">I'm surprised this doesn't produce a warning:<div><br></div><div><div>struct S</div><div>{</div><div><span style="white-space:pre-wrap">        </span>S(const int& i) : i(i) {}</div><div><span style="white-space:pre-wrap">    </span>const int& i;</div><div>};</div><div><br></div><div>void foo(long l)</div><div>{</div><div><span style="white-space:pre-wrap">       </span>S s(l); // binding a const ref to temporary</div><div>}</div><div><br></div><div>int main()</div><div>{</div><div><span style="white-space:pre-wrap">    </span>foo(1l);</div><div>}</div></div><div><br></div></div><br></blockquote><div>Why would that produce a warning?  You can bind an r-value to a const l-value reference.  And, function foo takes the parameter by value, so it is passing an l-value to the constructor of S.</div></div><br></div></div>