[cfe-dev] Missing warning when binding to const ref?

Daniel Dilts diltsman at gmail.com
Tue Apr 7 20:01:17 PDT 2015


On Tue, Apr 7, 2015 at 6:11 PM, Nikola Smiljanic <popizdeh at gmail.com> wrote:

> I'm surprised this doesn't produce a warning:
>
> struct S
> {
> S(const int& i) : i(i) {}
> const int& i;
> };
>
> void foo(long l)
> {
> S s(l); // binding a const ref to temporary
> }
>
> int main()
> {
> foo(1l);
> }
>
>
> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150407/f890a473/attachment.html>


More information about the cfe-dev mailing list