Menu

Access of moved variable

Fraser
2025-03-02
2025-03-06
  • Fraser

    Fraser - 2025-03-02

    The warning 'Access of moved variable other' comes up quite frequently when the code is ok. It occurs with move constructors when there are base classes. Could this be fixed?

    E.g;
    C::C(C &&other) noexcept :
    A(std::move(other)),
    B(std::move(other)),
    D(std::move(other)) {
    }

     
  • CHR

    CHR - 2025-03-02

    The example is incomplete. But how can moving three times from the same value be OK?

     
  • Fraser

    Fraser - 2025-03-03

    There is public inheritance of base classes A, B and D. The reference of C converts implicitly to a reference of A, B and D. The same warning also occurs with move assignment operators.

     
  • CHR

    CHR - 2025-03-06

    This still sounds dubious, but without a compilable example, it's hard to tell.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.