Skip to content

C.45: drop 'only' from the rule title - #2337

Open
simoes-tiobe wants to merge 1 commit into
isocpp:masterfrom
simoes-tiobe:c45-drop-only-in-title
Open

simoes-tiobe wants to merge 1 commit into
isocpp:masterfrom
simoes-tiobe:c45-drop-only-in-title

Conversation

@simoes-tiobe

@simoes-tiobe simoes-tiobe commented Sep 23, 2026 •

Copy link
Copy Markdown

Summary

The title of C.45 reads:

Don't define a default constructor that only initializes data members

Taken literally, "only" scopes the rule to constructors whose entire body does nothing but initialize — i.e. it suggests the constructor is disqualified as soon as it does anything else, or has any initializer that can't become a default member initializer.

But the Enforcement clause is already narrower and per-initializer:

(Simple) Flag if a default constructor's explicit member initializer is a constant, and recommend that the constant should be written as a data member initializer instead.

That is, each movable initializer should be flagged on its own merits, independent of the rest of the constructor. For example:

class Base {
public:
    explicit Base(int v) : b{v} {}
    int b{0};
};

class Y : public Base {
    int i;
public:
    Y() : Base{7}, i{1} {}   // Base{7} can't become a default member initializer,
                             // but i{1} should still be flagged and moved: int i{1};
};

Under the current title's "only" reading, Y's constructor could be misread as exempt (it does more than trivially initialize, since Base{7} requires an argument). Under the Enforcement clause as written, i{1} should still be flagged.

This PR drops "only" from the title (TOC entry and section heading) so the title no longer implies a whole-constructor, all-or-nothing scope that the Enforcement text doesn't actually require. No other wording changes.

The title's wording ('a default constructor that only initializes
data members') reads as scoping the rule to constructors whose entire
body does nothing but initialize. The Enforcement clause is already
narrower and per-initializer ('Flag if a default constructor's
explicit member initializer is a constant'), so a constructor with an
extra body statement, or with one initializer that can't be moved
(e.g. a base subobject needing a non-default initializer), should
still have its other movable initializers flagged. Dropping 'only'
removes the misleading implication without changing the Enforcement
text.
@hsutter

hsutter commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Editors call: Thanks! We agree that C.45's Enforcement doesn't match the title and body, which are about using the compiler generated default constructor when you can. We think the Enforcement should be moved to C.48 which covers the individual member initializer case, and C.45 should get a new Enforcement that focuses on using the compiler generated constructor when using member initializers makes that possible. I'll propose a new PR for this. Thanks for pointing this out!

@hsutter hsutter self-assigned this Oct 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants