From 2bd479044b796eaa9bff27ee019688fa551e7ea1 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 13 Mar 2019 02:12:48 +0200 Subject: [PATCH 1/8] Add spirit_conflict_test.cpp (refs #33) --- include/boost/endian/buffers.hpp | 4 ++-- test/Jamfile.v2 | 2 ++ test/spirit_conflict_test.cpp | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 test/spirit_conflict_test.cpp diff --git a/include/boost/endian/buffers.hpp b/include/boost/endian/buffers.hpp index 890919b..829d18b 100644 --- a/include/boost/endian/buffers.hpp +++ b/include/boost/endian/buffers.hpp @@ -290,7 +290,7 @@ namespace endian { T t; std::memcpy( &t, bytes, sizeof(T) ); - return endian::big_to_native(t); + return boost::endian::big_to_native(t); } # endif return unrolled_byte_loops::load_big @@ -324,7 +324,7 @@ namespace endian // (the x86 architecture allows unaligned loads, but -fsanitize=undefined does not) if (sizeof(T) == n_bytes) { - endian::native_to_big_inplace(value); + boost::endian::native_to_big_inplace(value); std::memcpy( bytes, &value, sizeof(T) ); return; } diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 3b12793..47ca215 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -43,3 +43,5 @@ run conversion_test.cpp : : : BOOST_ENDIAN_NO_INTRINSICS : conversion_te run intrinsic_test.cpp ; run quick.cpp ; + +compile spirit_conflict_test.cpp ; diff --git a/test/spirit_conflict_test.cpp b/test/spirit_conflict_test.cpp new file mode 100644 index 0000000..dc2c7c3 --- /dev/null +++ b/test/spirit_conflict_test.cpp @@ -0,0 +1,23 @@ +// Copyright 2019 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +#if defined(_MSC_VER) +# pragma warning( disable: 4510 ) // default constructor not generated +# pragma warning( disable: 4512 ) // assignment operator not generated +# pragma warning( disable: 4610 ) // class can never be instantiated +#endif + +#include +#include + +struct record +{ + boost::endian::big_int16_t type; + + record( boost::int16_t t ) + { + type = t; + } +}; From 3c6c06616d9684601a4b83577db25302d90d1570 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 13 Mar 2019 19:00:45 +0200 Subject: [PATCH 2/8] Disable warnings-as-errors=on for spirit_conflict_test --- test/Jamfile.v2 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 47ca215..1e4433d 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -44,4 +44,8 @@ run intrinsic_test.cpp ; run quick.cpp ; -compile spirit_conflict_test.cpp ; +compile spirit_conflict_test.cpp + : "-msvc:on" + "-gcc:on" + "-clang:on" + ; From 2d60299b7165f54a0b376ea5d60098806e4c0e24 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 18 Mar 2019 21:51:08 +0200 Subject: [PATCH 3/8] Add endian_reverse_test --- test/Jamfile.v2 | 13 ++- test/endian_reverse_test.cpp | 152 +++++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+), 4 deletions(-) create mode 100644 test/endian_reverse_test.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 1e4433d..f2fafcb 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -44,8 +44,13 @@ run intrinsic_test.cpp ; run quick.cpp ; -compile spirit_conflict_test.cpp - : "-msvc:on" +local allow-warnings = + "-msvc:on" "-gcc:on" - "-clang:on" - ; + "-clang:on" ; + +compile spirit_conflict_test.cpp + : $(allow-warnings) ; + +run endian_reverse_test.cpp + : : : $(allow-warnings) ; diff --git a/test/endian_reverse_test.cpp b/test/endian_reverse_test.cpp new file mode 100644 index 0000000..41737f3 --- /dev/null +++ b/test/endian_reverse_test.cpp @@ -0,0 +1,152 @@ +// Copyright 2019 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include +#include + +template struct test_value +{ +}; + +template struct test_value +{ + static const T v1 = static_cast( 0x1F ); + static const T w1 = static_cast( 0x1F ); + + static const T v2 = static_cast( 0xF1 ); + static const T w2 = static_cast( 0xF1 ); +}; + +template T const test_value::v1; +template T const test_value::w1; +template T const test_value::v2; +template T const test_value::w2; + +template struct test_value +{ + static const T v1 = static_cast( 0x1F2E ); + static const T w1 = static_cast( 0x2E1F ); + + static const T v2 = static_cast( 0xF1E2 ); + static const T w2 = static_cast( 0xE2F1 ); +}; + +template T const test_value::v1; +template T const test_value::w1; +template T const test_value::v2; +template T const test_value::w2; + +template struct test_value +{ + static const T v1 = static_cast( 0x1F2E3D4C ); + static const T w1 = static_cast( 0x4C3D2E1F ); + + static const T v2 = static_cast( 0xF1E2D3C4 ); + static const T w2 = static_cast( 0xC4D3E2F1 ); +}; + +template T const test_value::v1; +template T const test_value::w1; +template T const test_value::v2; +template T const test_value::w2; + +template struct test_value +{ + static const T v1 = static_cast( 0x1F2E3D4C5B6A7988ull ); + static const T w1 = static_cast( 0x88796A5B4C3D2E1Full ); + + static const T v2 = static_cast( 0xF1E2D3C4B5A69788ull ); + static const T w2 = static_cast( 0x8897A6B5C4D3E2F1ull ); +}; + +template T const test_value::v1; +template T const test_value::w1; +template T const test_value::v2; +template T const test_value::w2; + +template void test() +{ + using boost::endian::endian_reverse; + using boost::endian::endian_reverse_inplace; + + { + T t1 = test_value::v1; + + T t2 = endian_reverse( t1 ); + BOOST_TEST_EQ( t2, test_value::w1 ); + + T t3 = endian_reverse( t2 ); + BOOST_TEST_EQ( t3, t1 ); + + T t4 = t1; + + endian_reverse_inplace( t4 ); + BOOST_TEST_EQ( t4, test_value::w1 ); + + endian_reverse_inplace( t4 ); + BOOST_TEST_EQ( t4, t1 ); + } + + { + T t1 = test_value::v2; + + T t2 = endian_reverse( t1 ); + BOOST_TEST_EQ( t2, test_value::w2 ); + + T t3 = endian_reverse( t2 ); + BOOST_TEST_EQ( t3, t1 ); + + T t4 = t1; + + endian_reverse_inplace( t4 ); + BOOST_TEST_EQ( t4, test_value::w2 ); + + endian_reverse_inplace( t4 ); + BOOST_TEST_EQ( t4, t1 ); + } +} + +int main() +{ + test(); + test(); + + test(); + test(); + + test(); + test(); + + test(); + test(); + + test(); + test(); + test(); + + test(); + test(); + + test(); + test(); + + // test(); + // test(); + + test(); + test(); + +#if !defined(BOOST_NO_CXX11_CHAR16_T) + test(); +#endif + +#if !defined(BOOST_NO_CXX11_CHAR32_T) + test(); +#endif + + return boost::report_errors(); +} From 6a84756afb4269f391bba418b7e93fb919acb2e0 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 19 Mar 2019 00:40:01 +0200 Subject: [PATCH 4/8] Disable long long tests; disable C4309 on msvc --- test/endian_reverse_test.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/endian_reverse_test.cpp b/test/endian_reverse_test.cpp index 41737f3..dac1840 100644 --- a/test/endian_reverse_test.cpp +++ b/test/endian_reverse_test.cpp @@ -3,6 +3,10 @@ // Distributed under the Boost Software License, Version 1.0. // http://www.boost.org/LICENSE_1_0.txt +#if defined(_MSC_VER) +# pragma warning( disable: 4309 ) // static_cast: truncation of constant value +#endif + #include #include #include @@ -137,8 +141,8 @@ int main() // test(); // test(); - test(); - test(); + // test(); + // test(); #if !defined(BOOST_NO_CXX11_CHAR16_T) test(); From 01146c95588a4b98249101f98f09ec29027a79b5 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 19 Mar 2019 01:06:53 +0200 Subject: [PATCH 5/8] Add char and char16_t overloads of endian_reverse --- include/boost/endian/conversion.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/boost/endian/conversion.hpp b/include/boost/endian/conversion.hpp index 9da4225..a316a3d 100644 --- a/include/boost/endian/conversion.hpp +++ b/include/boost/endian/conversion.hpp @@ -282,6 +282,20 @@ namespace endian # endif } + // overloads for char and char16_t, which otherwise use int32_t + + inline char endian_reverse(char x) BOOST_NOEXCEPT + { + return static_cast( endian_reverse( static_cast(x) ) ); + } + +#if !defined(BOOST_NO_CXX11_CHAR16_T) + inline char16_t endian_reverse(char16_t x) BOOST_NOEXCEPT + { + return static_cast( endian_reverse( static_cast(x) ) ); + } +#endif + template inline EndianReversible big_to_native(EndianReversible x) BOOST_NOEXCEPT { From 185573f341ef5c5849c5a31294d9de06fe53f1c0 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 19 Mar 2019 04:22:24 +0200 Subject: [PATCH 6/8] Re-enable warnings as errors for endian_reverse_test --- test/Jamfile.v2 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index f2fafcb..e11ff22 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -52,5 +52,4 @@ local allow-warnings = compile spirit_conflict_test.cpp : $(allow-warnings) ; -run endian_reverse_test.cpp - : : : $(allow-warnings) ; +run endian_reverse_test.cpp ; From eee3e1bc7ab8f88f60ac99a7f2ad88c5149d9cca Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 19 Mar 2019 05:08:57 +0200 Subject: [PATCH 7/8] Update appveyor.yml --- appveyor.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index a7fd5eb..41c9c01 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -# Copyright 2016, 2017 Peter Dimov +# Copyright 2016-2019 Peter Dimov # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) @@ -18,13 +18,19 @@ environment: TOOLSET: msvc-9.0,msvc-10.0,msvc-11.0,msvc-12.0 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 TOOLSET: msvc-14.0 + ADDRMD: 32,64 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 TOOLSET: msvc-14.1 CXXSTD: 14,17 + ADDRMD: 32,64 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 ADDPATH: C:\cygwin\bin; TOOLSET: gcc CXXSTD: 03,11,14,1z + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + ADDPATH: C:\cygwin64\bin; + TOOLSET: gcc + CXXSTD: 03,11,14,1z - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 ADDPATH: C:\mingw\bin; TOOLSET: gcc @@ -41,7 +47,7 @@ install: - git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root - cd boost-root - git submodule update --init tools/boostdep - - xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\endian + - xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\endian\ - python tools/boostdep/depinst/depinst.py endian - cmd /c bootstrap - b2 -d0 headers @@ -51,4 +57,5 @@ build: off test_script: - PATH=%ADDPATH%%PATH% - if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD% - - b2 -j3 libs/endian/test toolset=%TOOLSET% %CXXSTD% variant=debug,release + - if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD% + - b2 -j3 libs/endian/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release From 6b65a4b6ed7ffe7450c2f3ca92da45a1d7053d7d Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 20 Mar 2019 02:25:54 +0200 Subject: [PATCH 8/8] Add endian_reverse_test_ni --- test/Jamfile.v2 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index e11ff22..ad97c98 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -1,7 +1,7 @@ # Boost Endian Library test Jamfile # Copyright Beman Dawes 2006, 2013 -# Copyright 2018 Peter Dimov +# Copyright 2018, 2019 Peter Dimov # Distributed under the Boost Software License, Version 1.0. # See http://www.boost.org/LICENSE_1_0.txt @@ -53,3 +53,4 @@ compile spirit_conflict_test.cpp : $(allow-warnings) ; run endian_reverse_test.cpp ; +run endian_reverse_test.cpp : : : BOOST_ENDIAN_NO_INTRINSICS : endian_reverse_test_ni ;