|
Boost : |
Subject: Re: [boost] [c++ question] detecting reference to temporaries
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2018-10-25 18:09:49
czw., 25 paź 2018 o 00:53 Raffi Enficiaud via Boost <boost_at_[hidden]>
napisaÅ(a):
> I have a stupid question related to a bug in boost.test. A piece of code
> is doing something like:
>
> const value& get() {
> return *internal_iterator; // can be a ref or not to value or another
> type
> }
>
> The fix is trivial, *but* I want to test it.
>
> Is there any technique that would let me test for reference to
> temporaries?
Test in one place or anywhere you are using references?
Does it have to work for pre-c++11 compilers? If not you can employ rvalue
references and deleted functions. I am using the following technique for
not binding temporaries to const-references in function arguments:
https://github.com/akrzemi1/explicit/blob/master/doc/lvalue_ref.md
Not exactly the same problem, but maybe the solution could be adapted.
The only option I see would be to promote compiler warnings
> into error, but maybe there is something there?
>
Making use of compiler warnings looks like a reasonable strategy to me.
Regards,
&rzej;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk