Empty special member should be = default

ID

c.maintainability.use_equals_default

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Modernization

Language

C / C++

Description

A default constructor or destructor with an empty body should be written = default;. The defaulted form documents intent, lets the compiler keep the type trivial where possible, and avoids accidentally suppressing move operations.

Rationale

A default constructor or destructor with an empty body should be written = default;. The defaulted form documents intent, lets the compiler keep the type trivial where possible, and avoids accidentally suppressing move operations.

The following code illustrates the pattern detected by this rule:

// Adapted from clang-tidy modernize-use-equals-default upstream test:
// clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default.cpp
struct A {
  // FLAGGED: Empty special member should be = default
  A() {}
  // FLAGGED: Empty special member should be = default
  ~A() {}
  void run() {}
};

struct B {

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.