[Bug c++/88050] Add a warning for breaking the "Rule of Three"
felix.von.s at posteo dot de
gcc-bugzilla@gcc.gnu.org
Thu Feb 10 09:14:26 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88050
felix <felix.von.s at posteo dot de> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |felix.von.s at posteo dot de
--- Comment #4 from felix <felix.von.s at posteo dot de> ---
Created attachment 52401
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52401&action=edit
Basic patch (no tests)
Attached is a simple patch adding a warning checks for violations of the Rule
of Three and the Rule of Five (Core Guideline C.21) and enabling it at the
-Wextra level.
Not included is a check for the rule-of-four-and-a-half variant: a swapping
by-value assignment operator overload, paired with the appropriate constructor,
is enough to implement copy- or move-assignment.
Rule of Zero would be much harder to check for, but it may be possible to
diagnose certain violations of it, by looking at the code inside the
destructor: if the delete operator, or a single function is invoked more than
once in the destructor, it probably means the class manages more than one
resource.
More information about the Gcc-bugs
mailing list