From ebc4d63d689c4f887c231c54add2625ca19aa279 Mon Sep 17 00:00:00 2001 From: Juha Reunanen Date: Tue, 19 Apr 2022 15:02:17 +0300 Subject: [PATCH] Workaround for #2506 (#2570) * Do not put variants that can hold immutable types to vectors * Enable build on gcc 11 --- .github/workflows/build_cpp.yml | 1 - dlib/test/serialize.cpp | 57 +++++++++++++++++++++------------ 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build_cpp.yml b/.github/workflows/build_cpp.yml index 5d0acf149..9e86b7799 100644 --- a/.github/workflows/build_cpp.yml +++ b/.github/workflows/build_cpp.yml @@ -36,7 +36,6 @@ jobs: run: cmake --build ${{ env.build_dir }} --config ${{ env.config }} --parallel 2 ubuntu-latest-gcc-11: - if: ${{ false }} # disabled until https://github.com/davisking/dlib/issues/2506 has been resolved runs-on: 'ubuntu-latest' steps: - uses: actions/checkout@v2 diff --git a/dlib/test/serialize.cpp b/dlib/test/serialize.cpp index 4fe70716c..89c1a37bd 100644 --- a/dlib/test/serialize.cpp +++ b/dlib/test/serialize.cpp @@ -448,7 +448,7 @@ namespace std::shared_ptr ptr_shared2; std::vector> p; #if __cplusplus >= 201703L - std::variant q; + std::variant q; std::optional> r; #endif @@ -1163,115 +1163,132 @@ namespace v1.v.push_back(t1); v1.v.push_back(t2); +#if __cplusplus >= 201703L + std::variant i1, i2; + i1 = std::string("hello from variant that can hold an immutable type"); +#else + // make it so that we don't need to add #if guards in every block below + std::string i1, i2; + i1 = "std::variant not supported"; +#endif { - dlib::serialize("serialization_test_macros.dat") << t1 << t2 << v1 << uptr1 << uptr2; - dlib::deserialize("serialization_test_macros.dat") >> t3 >> t4 >> v2 >> uptr3 >> uptr4; + dlib::serialize("serialization_test_macros.dat") << t1 << t2 << v1 << uptr1 << uptr2 << i1; + dlib::deserialize("serialization_test_macros.dat") >> t3 >> t4 >> v2 >> uptr3 >> uptr4 >> i2; DLIB_TEST(t1 == t3); DLIB_TEST(t2 == t4); DLIB_TEST(v1 == v2); DLIB_TEST(pointers_values_equal(uptr1, uptr3)); DLIB_TEST(pointers_values_equal(uptr2, uptr4)); + DLIB_TEST(i1 == i2); } { std::stringstream ss; - dlib::serialize(ss) << t1 << t2 << v1 << uptr1 << uptr2; - dlib::deserialize(ss) >> t3 >> t4 >> v2 >> uptr3 >> uptr4; + dlib::serialize(ss) << t1 << t2 << v1 << uptr1 << uptr2 << i1; + dlib::deserialize(ss) >> t3 >> t4 >> v2 >> uptr3 >> uptr4 >> i2; DLIB_TEST(t1 == t3); DLIB_TEST(t2 == t4); DLIB_TEST(v1 == v2); DLIB_TEST(pointers_values_equal(uptr1, uptr3)); DLIB_TEST(pointers_values_equal(uptr2, uptr4)); + DLIB_TEST(i1 == i2); } { std::ostringstream sout; - dlib::serialize(sout) << t1 << t2 << v1 << uptr1 << uptr2; + dlib::serialize(sout) << t1 << t2 << v1 << uptr1 << uptr2 << i1; std::istringstream sin(sout.str()); - dlib::deserialize(sin) >> t3 >> t4 >> v2 >> uptr3 >> uptr4; + dlib::deserialize(sin) >> t3 >> t4 >> v2 >> uptr3 >> uptr4 >> i2; DLIB_TEST(t1 == t3); DLIB_TEST(t2 == t4); DLIB_TEST(v1 == v2); DLIB_TEST(pointers_values_equal(uptr1, uptr3)); DLIB_TEST(pointers_values_equal(uptr2, uptr4)); + DLIB_TEST(i1 == i2); } { std::vector buf; - dlib::serialize(buf) << t1 << t2 << v1 << uptr1 << uptr2; - dlib::deserialize(buf) >> t3 >> t4 >> v2 >> uptr3 >> uptr4; + dlib::serialize(buf) << t1 << t2 << v1 << uptr1 << uptr2 << i1; + dlib::deserialize(buf) >> t3 >> t4 >> v2 >> uptr3 >> uptr4 >> i2; DLIB_TEST(t1 == t3); DLIB_TEST(t2 == t4); DLIB_TEST(v1 == v2); DLIB_TEST(pointers_values_equal(uptr1, uptr3)); DLIB_TEST(pointers_values_equal(uptr2, uptr4)); + DLIB_TEST(i1 == i2); } { std::vector buf; - dlib::serialize(buf) << t1 << t2 << v1 << uptr1 << uptr2; - dlib::deserialize(buf) >> t3 >> t4 >> v2 >> uptr3 >> uptr4; + dlib::serialize(buf) << t1 << t2 << v1 << uptr1 << uptr2 << i1; + dlib::deserialize(buf) >> t3 >> t4 >> v2 >> uptr3 >> uptr4 >> i2; DLIB_TEST(t1 == t3); DLIB_TEST(t2 == t4); DLIB_TEST(v1 == v2); DLIB_TEST(pointers_values_equal(uptr1, uptr3)); DLIB_TEST(pointers_values_equal(uptr2, uptr4)); + DLIB_TEST(i1 == i2); } { std::vector buf; - dlib::serialize(buf) << t1 << t2 << v1 << uptr1 << uptr2; - dlib::deserialize(buf) >> t3 >> t4 >> v2 >> uptr3 >> uptr4; + dlib::serialize(buf) << t1 << t2 << v1 << uptr1 << uptr2 << i1; + dlib::deserialize(buf) >> t3 >> t4 >> v2 >> uptr3 >> uptr4 >> i2; DLIB_TEST(t1 == t3); DLIB_TEST(t2 == t4); DLIB_TEST(v1 == v2); DLIB_TEST(pointers_values_equal(uptr1, uptr3)); DLIB_TEST(pointers_values_equal(uptr2, uptr4)); + DLIB_TEST(i1 == i2); } { std::vector buf1; - dlib::serialize(buf1) << t1 << t2 << v1 << uptr1 << uptr2; + dlib::serialize(buf1) << t1 << t2 << v1 << uptr1 << uptr2 << i1; std::vector buf2(buf1.begin(), buf1.end()); - dlib::deserialize(buf2) >> t3 >> t4 >> v2 >> uptr3 >> uptr4; + dlib::deserialize(buf2) >> t3 >> t4 >> v2 >> uptr3 >> uptr4 >> i2; DLIB_TEST(t1 == t3); DLIB_TEST(t2 == t4); DLIB_TEST(v1 == v2); DLIB_TEST(pointers_values_equal(uptr1, uptr3)); DLIB_TEST(pointers_values_equal(uptr2, uptr4)); + DLIB_TEST(i1 == i2); } { std::vector buf1; - dlib::serialize(buf1) << t1 << t2 << v1 << uptr1 << uptr2; + dlib::serialize(buf1) << t1 << t2 << v1 << uptr1 << uptr2 << i1; std::vector buf2(buf1.begin(), buf1.end()); - dlib::deserialize(buf2) >> t3 >> t4 >> v2 >> uptr3 >> uptr4; + dlib::deserialize(buf2) >> t3 >> t4 >> v2 >> uptr3 >> uptr4 >> i2; DLIB_TEST(t1 == t3); DLIB_TEST(t2 == t4); DLIB_TEST(v1 == v2); DLIB_TEST(pointers_values_equal(uptr1, uptr3)); DLIB_TEST(pointers_values_equal(uptr2, uptr4)); + DLIB_TEST(i1 == i2); } - { + { std::vector buf1; - dlib::serialize(buf1) << t1 << t2 << v1 << uptr1 << uptr2; + dlib::serialize(buf1) << t1 << t2 << v1 << uptr1 << uptr2 << i1; std::vector buf2(buf1.begin(), buf1.end()); - dlib::deserialize(buf2) >> t3 >> t4 >> v2 >> uptr3 >> uptr4; + dlib::deserialize(buf2) >> t3 >> t4 >> v2 >> uptr3 >> uptr4 >> i2; DLIB_TEST(t1 == t3); DLIB_TEST(t2 == t4); DLIB_TEST(v1 == v2); DLIB_TEST(pointers_values_equal(uptr1, uptr3)); DLIB_TEST(pointers_values_equal(uptr2, uptr4)); + DLIB_TEST(i1 == i2); } }