|
Boost : |
Subject: Re: [boost] How to deal with unused variable with a BOOST_ASSERT check?
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2017-09-10 10:31:17
On 09/09/2017 16:50, James E. King, III via Boost wrote:
> BOOST_ASSERT_ASSIGN_OR_IGNORE(std::codecvt_base::result r)
> m_codecvt_facet.out(
> m_mbs,
> & value, & value + 1, wend,
> m_buffer, m_buffer + sizeof(m_buffer), bend
> );
> BOOST_ASSERT(std::codecvt_base::ok == r);
>
> where BOOST_ASSERT_ASSIGN_OR_IGNORE would expand to, assuming
> BOOST_ASSERT_ACTIVE is an indicator whether assert code is compiled in:
>
> #if BOOST_ASSERT_ACTIVE
> std::codecvt_base::result r =
> #else
> (void)
> #endif
>
> This would allow me to eliminate the warning without submitting a PR that
> changes the behavior of the code. If something like this does not exist,
> would it be useful for me to add it to boostorg/assert, or would folks
> recommend against encouraging this behavior and instead change it to use
> exceptions?
I unconditionally write (void)r in my code after the assertion, and that
shuts the compiler. If you need to do more complicated things when the
assert is or not active, then use BOOST_ASSERT_IS_VOID:
http://www.boost.org/doc/libs/1_65_1/libs/assert/doc/html/assert.html#boost_assert_is_void
Ion
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk