• LLVM has many RAII classes that define destructors but omit copy constructors/assignments. • Implicit copying can cause double deletes, state corruption, and subtle bugs. • The Rule of Three mandates defining copy ctor/assignment when a destructor exists. • Rule of Zero applies to non‑ownership classes, avoiding custom special functions. • Rule of Five requires all five special functions if move semantics are needed. • Proposal: add Rule of Three to Code Standards and enable clang‑tidy check.

Article Summaries:

  • RFC: Enforce Rule of Three in LLVM

The LLVM community has proposed a new RFC to strengthen code safety by mandating the Rule of Three for RAII‑style classes that manage resources or state. The rule requires explicit definition (or deletion) of copy constructors and copy assignment operators whenever a destructor, copy constructor, or copy assignment is defined, preventing accidental copying that could lead to double‑deletion or state corruption. The RFC also suggests enabling the cppcoreguidelines-special-member-functions clang‑tidy check under a custom alias (llvm-rule-of-three) during pre‑commit testing, with AllowMissingMoveFunctionsWhenCopyIsDeleted set to true. Implementation would involve integrating this check into the existing clang‑tidy CI workflow, a task that the proposer offers to facilitate.

Sources: