Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NewType Copy-Assign raises compiler warning on GCC 8.4.0 #282

Closed
orecham opened this issue Sep 10, 2020 · 3 comments · Fixed by #923
Closed

NewType Copy-Assign raises compiler warning on GCC 8.4.0 #282

orecham opened this issue Sep 10, 2020 · 3 comments · Fixed by #923
Assignees
Labels
bug Something isn't working

Comments

@orecham
Copy link
Contributor

orecham commented Sep 10, 2020

Required information

Operating system:
Ubuntu 18.04 LTS

Compiler version:
GCC 8.4.0

Observed result or behaviour:
The following test for the NewType class in utils causes an incorrect compiler warning:

TEST(NewType, CopyAssignableDoesCompile)
{
    Sut<cxx::NewType<int, newtype::ConstructByValueCopy, newtype::CopyAssignable, newtype::Comparable>> a(491), b(492),
        c(423);
    b = a;
    EXPECT_TRUE(a == b);
}

The warning "deprecated-copy" is raised at b = a; despite the NewType having no deprecated copy constructor.
The source of the error might be elsewhere but this is not clear to me.

GCC 8.4.0 is what is used on the Github Workflow VM so this test causes the build to fail and thus blocks merges.

Expected result or behaviour:
This code should compile without warning.

Conditions where it occurred / Performed steps:
Compile on GCC 8.4.0

@mossmaurice mossmaurice added the bug Something isn't working label Mar 5, 2021
@dkroenke
Copy link
Member

@ithier On latest master and release 1.0 this warning does not come up, I will close this here for now.

@elBoberido
Copy link
Member

@dkroenke I think this is because we use this ugly #pragma GCC diagnostic ignored "-Wdeprecated-copy". It's currently only an issue in test_cxx_newtype.cpp because it is not used anywhere else with the copy constructor. There is an easy fix for this though, we just have to create the class like this

struct Foo : public cxx::NewType<...>
{
    /* this is already in the documentation of the NewType pattern */
    using ThisType::ThisType;
    using ThisType::operator=; // bring all operator= into scope

   /* this is new */
    // implement copy and move ctors when they are implemented by the base class
    Foo(const Foo&) = default;
    Foo(Foo&&) = default;

    // implement copy and move assingment when they are implemented by the base class
    Foo& operator=(const Foo&) = default;
    Foo& operator=(Foo&&) = default;
};

@elfenpiff @MatthiasKillat do you think there are any reasons not to do it as suggested?

@elfenpiff
Copy link
Contributor

@elBoberido no I am fine with this :D

@elBoberido elBoberido reopened this Sep 7, 2021
elBoberido added a commit to ApexAI/iceoryx that referenced this issue Sep 7, 2021
@elBoberido elBoberido self-assigned this Sep 7, 2021
elBoberido added a commit to ApexAI/iceoryx that referenced this issue Sep 7, 2021
elBoberido added a commit to ApexAI/iceoryx that referenced this issue Sep 8, 2021
elBoberido added a commit that referenced this issue Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants