[c++ question] detecting reference to temporaries
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? The only option I see would be to promote compiler warnings into error, but maybe there is something there? Thanks, Raffi (complete example here: https://github.com/boostorg/test/blob/90d577a620e008417af79f5caa25e701eef954... )
czw., 25 paź 2018 o 00:53 Raffi Enficiaud via Boost
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;
participants (2)
-
Andrzej Krzemienski
-
Raffi Enficiaud