You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CppCoreGuidelines.md
+15-15Lines changed: 15 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# <a name="main"></a>C++ Core Guidelines
2
2
3
-
May 28, 2020
3
+
July 3, 2020
4
4
5
5
6
6
Editors:
@@ -314,7 +314,7 @@ The rules are not value-neutral.
314
314
They are meant to make code simpler and more correct/safer than most existing C++ code, without loss of performance.
315
315
They are meant to inhibit perfectly valid C++ code that correlates with errors, spurious complexity, and poor performance.
316
316
317
-
The rules are not precise to the point where a person (or machine) can follow them blindly.
317
+
The rules are not precise to the point where a person (or machine) can follow them without thinking.
318
318
The enforcement parts try to be that, but we would rather leave a rule or a definition a bit vague
319
319
and open to interpretation than specify something precisely and wrong.
320
320
Sometimes, precision comes only with time and experience.
@@ -352,7 +352,7 @@ We try to resolve those using tools.
352
352
Each rule has an **Enforcement** section listing ideas for enforcement.
353
353
Enforcement might be done by code review, by static analysis, by compiler, or by run-time checks.
354
354
Wherever possible, we prefer "mechanical" checking (humans are slow, inaccurate, and bore easily) and static checking.
355
-
Run-time checks are suggested only rarely where no alternative exists; we do not want to introduce "distributed fat".
355
+
Run-time checks are suggested only rarely where no alternative exists; we do not want to introduce "distributed bloat".
356
356
Where appropriate, we label a rule (in the **Enforcement** sections) with the name of groups of related rules (called "profiles").
357
357
A rule can be part of several profiles, or none.
358
358
For a start, we have a few profiles corresponding to common needs (desires, ideals):
@@ -4724,7 +4724,7 @@ These operations disagree about copy semantics. This will lead to confusion and
4724
4724
4725
4725
## <a name="SS-dtor"></a>C.dtor: Destructors
4726
4726
4727
-
"Does this class need a destructor?" is a surprisingly powerful design question.
4727
+
"Does this class need a destructor?" is a surprisingly insightful design question.
4728
4728
For most classes the answer is "no" either because the class holds no resources or because destruction is handled by [the rule of zero](#Rc-zero);
4729
4729
that is, its members can take care of themselves as concerns destruction.
4730
4730
If the answer is "yes", much of the design of the class follows (see [the rule of five](#Rc-five)).
@@ -5561,7 +5561,7 @@ Makes it explicit that the same value is expected to be used in all constructors
5561
5561
// ...
5562
5562
};
5563
5563
5564
-
How would a maintainer know whether `j` was deliberately uninitialized (probably a poor idea anyway) and whether it was intentional to give `s` the default value `""` in one case and `qqq` in another (almost certainly a bug)? The problem with `j` (forgetting to initialize a member) often happens when a new member is added to an existing class.
5564
+
How would a maintainer know whether `j` was deliberately uninitialized (probably a bad idea anyway) and whether it was intentional to give `s` the default value `""` in one case and `qqq` in another (almost certainly a bug)? The problem with `j` (forgetting to initialize a member) often happens when a new member is added to an existing class.
5565
5565
5566
5566
##### Example
5567
5567
@@ -6710,7 +6710,7 @@ In particular, ensure that an object compares equal to its copy.
6710
6710
{
6711
6711
Sorted_vector<string> v2 {v};
6712
6712
if (v != v2)
6713
-
cout << "insanity rules!\n";
6713
+
cout << "Behavior against reason and logic.\n";
6714
6714
// ...
6715
6715
}
6716
6716
@@ -8720,7 +8720,7 @@ but at least we can see that something tricky is going on.
8720
8720
##### Note
8721
8721
8722
8722
Unfortunately, `union`s are commonly used for type punning.
8723
-
We don't consider "sometimes, it works as expected" a strong argument.
8723
+
We don't consider "sometimes, it works as expected" a conclusive argument.
8724
8724
8725
8725
C++17 introduced a distinct type `std::byte` to facilitate operations on raw object representation. Use that type instead of `unsigned char` or `char` for these operations.
8726
8726
@@ -10688,7 +10688,7 @@ Readability. Limit the scope in which a variable can be used. Don't risk used-be
This section contains rules for people who need high performance or low-latency.
13434
13434
That is, these are rules that relate to how to use as little time and as few resources as possible to achieve a task in a predictably short time.
13435
13435
The rules in this section are more restrictive and intrusive than what is needed for many (most) applications.
13436
-
Do not blindly try to follow them in general code: achieving the goals of low latency requires extra work.
13436
+
Do not naïvely try to follow them in general code: achieving the goals of low latency requires extra work.
13437
13437
13438
13438
Performance rule summary:
13439
13439
@@ -14707,7 +14707,7 @@ Thread creation is expensive.
14707
14707
// process
14708
14708
}
14709
14709
14710
-
void master(istream& is)
14710
+
void dispatcher(istream& is)
14711
14711
{
14712
14712
for (Message m; is >> m; )
14713
14713
run_list.push_back(new thread(worker, m));
@@ -14719,7 +14719,7 @@ Instead, we could have a set of pre-created worker threads processing the messag
14719
14719
14720
14720
Sync_queue<Message> work;
14721
14721
14722
-
void master(istream& is)
14722
+
void dispatcher(istream& is)
14723
14723
{
14724
14724
for (Message m; is >> m; )
14725
14725
work.put(m);
@@ -18126,7 +18126,7 @@ Templating a class hierarchy that has many functions, especially many virtual fu
18126
18126
Vector<int> vi;
18127
18127
Vector<string> vs;
18128
18128
18129
-
It is probably a dumb idea to define a `sort` as a member function of a container, but it is not unheard of and it makes a good example of what not to do.
18129
+
It is probably a bad idea to define a `sort` as a member function of a container, but it is not unheard of and it makes a good example of what not to do.
18130
18130
18131
18131
Given this, the compiler cannot know if `vector<int>::sort()` is called, so it must generate code for it.
18132
18132
Similar for `vector<string>::sort()`.
@@ -20107,7 +20107,7 @@ However, in the context of the styles of programming we recommend and support wi
20107
20107
20108
20108
Even today, there can be contexts where the rules make sense.
20109
20109
For example, lack of suitable tool support can make exceptions unsuitable in hard-real-time systems,
20110
-
but please don't blindly trust "common wisdom" (e.g., unsupported statements about "efficiency");
20110
+
but please don't naïvely trust "common wisdom" (e.g., unsupported statements about "efficiency");
20111
20111
such "wisdom" may be based on decades-old information or experienced from languages with very different properties than C++
20112
20112
(e.g., C or Java).
20113
20113
@@ -21945,7 +21945,7 @@ Never allow an error to be reported from a destructor, a resource deallocation f
21945
21945
21946
21946
Here, copying `s` could throw, and if that throws and if `n`'s destructor then also throws, the program will exit via `std::terminate` because two exceptions can't be propagated simultaneously.
21947
21947
21948
-
2. Classes with `Nefarious` members or bases are also hard to use safely, because their destructors must invoke `Nefarious`' destructor, and are similarly poisoned by its poor behavior:
21948
+
2. Classes with `Nefarious` members or bases are also hard to use safely, because their destructors must invoke `Nefarious`' destructor, and are similarly poisoned by its bad behavior:
21949
21949
21950
21950
21951
21951
class Innocent_bystander {
@@ -21955,7 +21955,7 @@ Never allow an error to be reported from a destructor, a resource deallocation f
0 commit comments