Skip to content

clang-tidy cppcoreguidelines-special-member-functions should encourage rule of zero #151005

@peakschris

Description

@peakschris

The current wording in cppcoreguidelines-special-member-functions description and documentation encourages classes with a default or no-op destructor to be converted into rule of five classes.

Take:

myclass.hxx

class myclass
{
    myclass();
    ~myclass();
}

myclass.cxx

myclass::~myclass()
{
}

clang-tidy on cxx yields:
Use '= default' to define a trivial destructor (fix available)

clang-tidy on hxx yields:
Class 'myclass' defines a destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator

Neither message encourages the developer to remove the destructor hence creating a rule-of-zero class as per: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-zero

Both messages encourage a new developer to add special functions instead.

Perhaps this requires a custom rule-of-zero check

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