Skip to content

cppcoreguidelines-special-member-functions requires default destructors when move and copy are deleted #104553

@fekir

Description

@fekir

Consider following class

    class c
    {
    public:
      int a;
      int b;

      c( int a1, int b1 )
          : a{ a1 }
          , b{ b1 }
      {
      }
      c( const c& ) = delete;
      c& operator=( const c& ) = delete;
      c( c&& ) = delete;
      c& operator=( c&& ) = delete;
};

clang-tidy, with cppcoreguidelines-special-member-functions claims that one should also define the destructor

warning: class 'c' defines a copy constructor and a copy assignment operator but does not define a destructor [cppcoreguidelines-special-member-functions]

I think it might be beneficial to avoid defining ~c() = default.
Contrary to move and copy operations, destruction is a little bit different.
I am currently not able to think about one use-case where adding a defaulted destructor helps to clarify what this class does.

Would it be possible to not to warn for non-user-defined destructors when copy and move operators are deleted?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions