Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CppCoreGuidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -5898,7 +5898,7 @@ Using default member initializers lets the compiler generate the function for yo

##### Enforcement

(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.
(Simple) Flag if a default constructor only initializes members, and recommend that the initializers should be written as data member initializers instead and the compiler-generated default constructor used

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be more resticted like "Flag if a default constructor only initializes members from simple expressions, ..."

I think these examples should not use data memeber initializers:

    double a {cos(.1)};   // requires header for cos when it is only an implementation detail
    MyType b {InternalFunction()}; // also requires implementaion to be known in header
    time_point<system_clock> creationTime{ system_clock::now() };  // dynamic

creationTime example was in #2332


### <a name="rc-explicit"></a>C.46: By default, declare single-argument constructors explicit

Expand Down Expand Up @@ -6010,6 +6010,8 @@ How would a maintainer know whether `j` was deliberately uninitialized (probably

* (Simple) Every constructor should initialize every data member (either explicitly, via a delegating ctor call or via default construction).
* (Simple) Default arguments to constructors suggest a default member initializer might be more appropriate.
* (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.


### <a name="rc-initialize"></a>C.49: Prefer initialization to assignment in constructors

Expand Down
Loading