Skip to content

Commit 051c59d

Browse files
author
Andrew Pardoe
committed
Merge branch 'tkruse-style-fix26'
2 parents 14ec6c7 + 2a95737 commit 051c59d

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

CppCoreGuidelines.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ The second version leaves the reader guessing and opens more possibilities for u
371371

372372
##### Example
373373

374-
void do_something(vector<string>& v)
374+
void f(vector<string>& v)
375375
{
376376
string val;
377377
cin >> val;
@@ -388,7 +388,7 @@ The second version leaves the reader guessing and opens more possibilities for u
388388
That loop is a restricted form of `std::find`.
389389
A much clearer expression of intent would be:
390390

391-
void do_something(vector<string>& v)
391+
void f(vector<string>& v)
392392
{
393393
string val;
394394
cin >> val;
@@ -2315,13 +2315,13 @@ When copying is cheap, nothing beats the simplicity and safety of copying, and f
23152315

23162316
##### Example
23172317

2318-
void f(const string& s); // OK: pass by reference to const; always cheap
2318+
void f1(const string& s); // OK: pass by reference to const; always cheap
23192319

2320-
void f2(string s); // bad: potentially expensive
2320+
void f2(string s); // bad: potentially expensive
23212321

2322-
void f3(int x); // OK: Unbeatable
2322+
void f3(int x); // OK: Unbeatable
23232323

2324-
void f4(const int& x); // bad: overhead on access in f4()
2324+
void f4(const int& x); // bad: overhead on access in f4()
23252325

23262326
For advanced uses (only), where you really need to optimize for rvalues passed to "input-only" parameters:
23272327

@@ -4707,7 +4707,7 @@ If the state of a base class object must depend on the state of a derived part o
47074707
}
47084708
};
47094709

4710-
class D : public B { /* */ }; // some derived class
4710+
class D : public B { /* ... */ }; // some derived class
47114711

47124712
shared_ptr<D> p = D::Create<D>(); // creating a D object
47134713

@@ -5739,13 +5739,13 @@ Such as on an ABI (link) boundary.
57395739
};
57405740

57415741
class D2 : public Device {
5742-
// ... differnt data ...
5743-
5742+
// ... different data ...
5743+
57445744
void write(span<const char> outbuf) override;
57455745
void read(span<char> inbuf) override;
57465746
};
57475747

5748-
A user can now use `D1`s and `D2`s interrchangeably through the interface provided by `Device`.
5748+
A user can now use `D1`s and `D2`s interchangeably through the interface provided by `Device`.
57495749
Furthermore, we can update `D1` and `D2` in a ways that are not binarily compatible with older versions as long as all access goes through `Device`.
57505750

57515751
##### Enforcement
@@ -6745,7 +6745,7 @@ Readability. Convention. Reusability. Support for generic code
67456745
return os << /* class members here */;
67466746
}
67476747

6748-
By itself, `cout_my_class` would be OK, but it is not usable/composabe with code that rely on the `<<` convention for output:
6748+
By itself, `cout_my_class` would be OK, but it is not usable/composable with code that rely on the `<<` convention for output:
67496749

67506750
My_class var { /* ... */ };
67516751
// ...
@@ -7027,7 +7027,7 @@ Here, we ignore such cases.
70277027
* [R.30: Take smart pointers as parameters only to explicitly express lifetime semantics](#Rr-smartptrparam)
70287028
* [R.31: If you have non-`std` smart pointers, follow the basic pattern from `std`](#Rr-smart)
70297029
* [R.32: Take a `unique_ptr<widget>` parameter to express that a function assumes ownership of a `widget`](#Rr-uniqueptrparam)
7030-
* [R.33: Take a `unique_ptr<widget>&` parameter to express that a function reseats the`widget`](#Rr-reseat)
7030+
* [R.33: Take a `unique_ptr<widget>&` parameter to express that a function reseats the `widget`](#Rr-reseat)
70317031
* [R.34: Take a `shared_ptr<widget>` parameter to express that a function is part owner](#Rr-sharedptrparam-owner)
70327032
* [R.35: Take a `shared_ptr<widget>&` parameter to express that a function might reseat the shared pointer](#Rr-sharedptrparam)
70337033
* [R.36: Take a `const shared_ptr<widget>&` parameter to express that it might retain a reference count to the object ???](#Rr-sharedptrparam-const)
@@ -7272,7 +7272,7 @@ The members of a scoped object are themselves scoped and the scoped object's con
72727272

72737273
##### Example
72747274

7275-
The following example is inefficient (because it has unnecessary allocation and deallocation), vulnerable to exception throws and returns in the part (leading to leaks), and verbose:
7275+
The following example is inefficient (because it has unnecessary allocation and deallocation), vulnerable to exception throws and returns in the `...` part (leading to leaks), and verbose:
72767276

72777277
void f(int n)
72787278
{
@@ -8445,7 +8445,7 @@ solution:
84458445
j = f4();
84468446
}
84478447

8448-
Now the compiler cannot even simply detect a used-before-set. Further, we've introduced complexity in the state space for widget: which operations are valid on an `unint` widget and which are not?
8448+
Now the compiler cannot even simply detect a used-before-set. Further, we've introduced complexity in the state space for widget: which operations are valid on an `uninit` widget and which are not?
84498449

84508450
##### Note
84518451

@@ -9127,7 +9127,7 @@ It is easy to overlook the fallthrough. Be explicit:
91279127
break;
91289128
case Warning:
91299129
write_event_log();
9130-
// fall through
9130+
// fallthrough
91319131
case Error:
91329132
display_error_window(); // Bad
91339133
break;
@@ -9149,7 +9149,7 @@ Multiple case labels of a single statement is OK:
91499149

91509150
##### Enforcement
91519151

9152-
Flag all fall throughs from non-empty `case`s.
9152+
Flag all fallthroughs from non-empty `case`s.
91539153

91549154
### <a name="Res-default"></a>ES.79: ??? `default`
91559155

@@ -10869,7 +10869,7 @@ Let cleanup actions on the unwinding path be handled by [RAII](#Re-raii).
1086910869

1087010870
This code is messy.
1087110871
There could be a leak from the naked pointer in the `try` block.
10872-
Not all exceptiones are handled.
10872+
Not all exceptions are handled.
1087310873
`deleting` an object that failed to construct is almost certainly a mistake.
1087410874
Better:
1087510875

@@ -10916,8 +10916,8 @@ Even without exceptions, [RAII](#Re-raii) is usually the best and most systemati
1091610916
##### Note
1091710917

1091810918
Error handling using exceptions is the only complete and systematic way of handling non-local errors in C++.
10919-
In particular, non-intrusively signalling failure to construct an object requires an exception.
10920-
Signalling errors in a way that cannot be ignored requires exceptions.
10919+
In particular, non-intrusively signaling failure to construct an object requires an exception.
10920+
Signaling errors in a way that cannot be ignored requires exceptions.
1092110921
If you can't use exceptions, simulate their use as best you can.
1092210922

1092310923
A lot of fear of exceptions is misguided.
@@ -10986,7 +10986,7 @@ In such cases, "crashing" is simply leaving error handling to the next level of
1098610986

1098710987
##### Example
1098810988

10989-
void do_something(int n)
10989+
void f(int n)
1099010990
{
1099110991
// ...
1099210992
p = static_cast<X*>(malloc(n, X));
@@ -10996,7 +10996,7 @@ In such cases, "crashing" is simply leaving error handling to the next level of
1099610996

1099710997
Most systems cannot handle memory exhaustion gracefully anyway. This is roughly equivalent to
1099810998

10999-
void do_something(Int n)
10999+
void f(Int n)
1100011000
{
1100111001
// ...
1100211002
p = new X[n]; // throw if memory is exhausted (by default, terminate)
@@ -11093,7 +11093,7 @@ and to avoid confusion with other uses of `std::pair`.
1109311093

1109411094
###### Example
1109511095

11096-
In general, you must clean up before an eror exit.
11096+
In general, you must clean up before an error exit.
1109711097
This can be messy:
1109811098

1109911099
std::pair<int, error_indicator> user()
@@ -11123,7 +11123,7 @@ This can be messy:
1112311123
}
1112411124

1112511125
Simulating RAII can be non-trivial, especially in functions with multiple resources and multiple possible errors.
11126-
A not uncommon technique is to gather cleanup at the end of the function to avoid repetittion:
11126+
A not uncommon technique is to gather cleanup at the end of the function to avoid repetition:
1112711127

1112811128
std::pair<int, error_indicator> user()
1112911129
{
@@ -11154,7 +11154,7 @@ A not uncommon technique is to gather cleanup at the end of the function to avoi
1115411154
}
1115511155

1115611156
The larger the function, the more tempting this technique becomes.
11157-
Aso, the larger the program becomes the harder it is to apply an error-indicator-based error handling strategy systematically.
11157+
Also, the larger the program becomes the harder it is to apply an error-indicator-based error handling strategy systematically.
1115811158

1115911159
We [prefer exception-based error handling](#Re-throw) and recommend [keeping functions short](#Rf-single).
1116011160

@@ -11179,7 +11179,7 @@ See also [Simulating RAII](#Re-no-throw-raii).
1117911179

1118011180
##### Note
1118111181

11182-
C-stye error handling is based on the global variable `errno`, so it is essentially impossible to avoid this style completely.
11182+
C-style error handling is based on the global variable `errno`, so it is essentially impossible to avoid this style completely.
1118311183

1118411184
##### Enforcement
1118511185

@@ -12040,10 +12040,10 @@ In general, passing function objects gives better performance than passing point
1204012040
auto y = find_if(v, [](double x) { return x > 7; }); // function object: carries the needed data
1204112041
auto z = find_if(v, Greater_than<double>(7)); // function object: carries the needed data
1204212042

12043-
You can, of course, gneralize those functions using `auto` or (when and where available) concepts. For example:
12043+
You can, of course, generalize those functions using `auto` or (when and where available) concepts. For example:
1204412044

12045-
auto y1 = find_if(v, [](Ordered x) { return x > 7; }); // reruire an ordered type
12046-
auto z1 = find_if(v, [](auto x) { return x > 7; }); // hope that the type has a >
12045+
auto y1 = find_if(v, [](Ordered x) { return x>7; }); // require an ordered type
12046+
auto z1 = find_if(v, [](auto x) { return x>7; }); // hope that the type has a >
1204712047

1204812048
##### Note
1204912049

@@ -12230,7 +12230,7 @@ Flag uses where an explicitly specialized type exactly matches the types of the
1223012230
X(X&&); // move
1223112231
X& operator=(X&&);
1223212232
~X();
12233-
// ... no moreconstructors ...
12233+
// ... no more constructors ...
1223412234
};
1223512235

1223612236
X x {1}; // fine
@@ -12262,7 +12262,7 @@ Semiregular requires default constructible.
1226212262
}
1226312263

1226412264
namespace T0 {
12265-
bool operator==(int, Bad::S) { cout << "T0\n"; return true; } // compate to int
12265+
bool operator==(int, Bad::S) { cout << "T0\n"; return true; } // compare to int
1226612266

1226712267
void test()
1226812268
{
@@ -15691,7 +15691,7 @@ Alternatively, we will decide that no change is needed and delete the entry.
1569115691
* How granular should namespaces be? All classes/functions designed to work together and released together (as defined in Sutter/Alexandrescu) or something narrower or wider?
1569215692
* Should there be inline namespaces (à la `std::literals::*_literals`)?
1569315693
* Avoid implicit conversions
15694-
* Const member functions should be thread safe aka, but I don't really change the variable, just assign it a value the first time it’s called argh
15694+
* Const member functions should be thread safe ... aka, but I don't really change the variable, just assign it a value the first time it’s called ... argh
1569515695
* Always initialize variables, use initialization lists for member variables.
1569615696
* Anyone writing a public interface which takes or returns `void*` should have their toes set on fire. That one has been a personal favorite of mine for a number of years. :)
1569715697
* Use `const`-ness wherever possible: member functions, variables and (yippee) `const_iterators`

0 commit comments

Comments
 (0)