Skip to content

Commit

Permalink
Work around MSVC warnings in test code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lastique committed Oct 19, 2024
1 parent 0ed0a5d commit d5914e3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
20 changes: 19 additions & 1 deletion test/api_test_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,12 @@ void test_additive_operators_with_type_and_test()
#pragma warning(pop)
#endif

#if defined(BOOST_MSVC)
#pragma warning(push)
// cast truncates constant value
#pragma warning(disable: 4310)
#endif

template< template< typename > class Wrapper, typename T, typename D, typename AddType >
void test_additive_operators_with_type(T value, D delta)
{
Expand Down Expand Up @@ -698,6 +704,10 @@ void test_additive_operators_with_type(T value, D delta)
test_additive_operators_with_type_and_test< Wrapper, T, D, AddType >();
}

#if defined(BOOST_MSVC)
#pragma warning(pop)
#endif

template< template< typename > class Wrapper, typename T, typename D >
void test_additive_operators(T value, D delta)
{
Expand Down Expand Up @@ -1169,7 +1179,15 @@ void do_test_integral_api(boost::false_type)
{
test_base_operators< Wrapper, T >(42, 43, 44);
test_additive_operators< Wrapper, T, T >(42, 17);
#if defined(BOOST_MSVC)
#pragma warning(push)
// cast truncates constant value
#pragma warning(disable: 4310)
#endif
test_bit_operators< Wrapper, T >((T)0x5f5f5f5f5f5f5f5fULL, (T)0xf5f5f5f5f5f5f5f5ULL);
#if defined(BOOST_MSVC)
#pragma warning(pop)
#endif

/* test for unsigned overflow/underflow */
test_additive_operators< Wrapper, T, T >((T)-1, 1);
Expand All @@ -1185,7 +1203,7 @@ void do_test_integral_api(boost::true_type)
do_test_integral_api< Wrapper, T >(boost::false_type());

test_additive_wrap< Wrapper, T >(0u);
BOOST_CONSTEXPR_OR_CONST T all_ones = ~(T)0u;
BOOST_CONSTEXPR_OR_CONST T all_ones = (T)-1;
test_additive_wrap< Wrapper, T >(all_ones);
BOOST_CONSTEXPR_OR_CONST T max_signed_twos_compl = all_ones >> 1;
test_additive_wrap< Wrapper, T >(all_ones ^ max_signed_twos_compl);
Expand Down
9 changes: 5 additions & 4 deletions test/atomic_ref_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ int main(int, char *[])
test_struct_with_padding_api< atomic_ref_wrapper >();
#endif

aligned_object< const int, boost::atomic_ref< const int >::required_alignment > object(10);
boost::atomic_ref< const int > r(object.get());
BOOST_TEST_EQ(r.load(boost::memory_order_relaxed), 10);

{
aligned_object< const int, boost::atomic_ref< const int >::required_alignment > object(10);
boost::atomic_ref< const int > r(object.get());
BOOST_TEST_EQ(r.load(boost::memory_order_relaxed), 10);
}
#if !defined(BOOST_NO_CXX17_DEDUCTION_GUIDES)
if (boost::atomic_ref< int >::is_always_lock_free)
{
Expand Down
5 changes: 5 additions & 0 deletions test/lockfree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
#include <boost/core/lightweight_test.hpp>
#include "aligned_object.hpp"

#if defined(BOOST_MSVC)
// conditional expression is constant
#pragma warning(disable: 4127)
#endif

static const char* const lock_free_level[] =
{
"never",
Expand Down

0 comments on commit d5914e3

Please sign in to comment.