Skip to content

Commit

Permalink
iox-eclipse-iceoryx#282 Fix deprecated-copy warning
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Sep 7, 2021
1 parent a8c40c4 commit 31647f2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
8 changes: 8 additions & 0 deletions iceoryx_hoofs/include/iceoryx_hoofs/cxx/newtype.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ namespace cxx
/// // otherwise the code will not compile
/// using ThisType::ThisType; // this makes all constructors of NewType available for Index
/// using ThisType::operator=; // put the assignment operators in scope
///
/// // implement ctors and assignment operators when they are implemented by the base class
/// // this is necessary pro prevent warnings from specific compilers
/// Index() noexcept = default;
/// Index(const Index&) noexcept = default;
/// Index(Index&&) noexcept = default;
/// Index& operator=(const Index&) noexcept = default;
/// Index& operator=(Index&&) noexcept = default;
/// };
///
/// Index a(123), c(456); // allowed since we are using the policy ConstructByValueCopy
Expand Down
19 changes: 8 additions & 11 deletions iceoryx_hoofs/test/moduletests/test_cxx_newtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ struct Sut : public T
{
using T::T;
using T::operator=; // bring all operator= into scope

// implement ctors and assignment operators when they are implemented by the base class
// this is necessary pro prevent warnings from specific compilers
Sut() noexcept = default;
Sut(const Sut&) noexcept = default;
Sut(Sut&&) noexcept = default;
Sut& operator=(const Sut&) noexcept = default;
Sut& operator=(Sut&&) noexcept = default;
};

static CompileTest compileTest(R"(
Expand Down Expand Up @@ -89,19 +97,8 @@ TEST(NewType, CopyAssignableDoesCompile)
Sut<cxx::NewType<int, newtype::ConstructByValueCopy, newtype::CopyAssignable, newtype::Comparable>> a(491), b(492),
c(423);

// Ignore false positive
// See: https://isocpp.org/wiki/faq/strange-inheritance#hiding-rule

#if (__GNUC__ == 9 && (__GNUC_MINOR__ > 1 || (__GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL__ > 0)))

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-copy"
b = a;
#pragma GCC diagnostic pop
EXPECT_TRUE(a == b);
#else
// Test disabled.
#endif
}

TEST(NewType, MoveConstructableDoesCompile)
Expand Down

0 comments on commit 31647f2

Please sign in to comment.