Skip to content

Commit bbc2f4d

Browse files
authored
Merge branch 'master' into patch-1
2 parents 30ef5b8 + 9864022 commit bbc2f4d

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

CppCoreGuidelines.md

+23-21
Original file line numberDiff line numberDiff line change
@@ -4492,7 +4492,7 @@ Destructor rules:
44924492
* [C.30: Define a destructor if a class needs an explicit action at object destruction](#Rc-dtor)
44934493
* [C.31: All resources acquired by a class must be released by the class's destructor](#Rc-dtor-release)
44944494
* [C.32: If a class has a raw pointer (`T*`) or reference (`T&`), consider whether it might be owning](#Rc-dtor-ptr)
4495-
* [C.33: If a class has an owning pointer member, define or `=delete` a destructor](#Rc-dtor-ptr2)
4495+
* [C.33: If a class has an owning pointer member, define a destructor](#Rc-dtor-ptr2)
44964496
* [C.35: A base class destructor should be either public and virtual, or protected and non-virtual](#Rc-dtor-virtual)
44974497
* [C.36: A destructor may not fail](#Rc-dtor-fail)
44984498
* [C.37: Make destructors `noexcept`](#Rc-dtor-noexcept)
@@ -12698,7 +12698,7 @@ consider `gsl::finally()` as a cleaner and more reliable alternative to `goto ex
1269812698

1269912699
switch(x){
1270012700
case 1 :
12701-
while(/* some condition */){
12701+
while (/* some condition */) {
1270212702
//...
1270312703
break;
1270412704
} //Oops! break switch or break while intended?
@@ -12715,8 +12715,8 @@ Often, a loop that requires a `break` is a good candidate for a function (algori
1271512715
void use1(){
1271612716
std::vector<T> vec = {/* initialized with some values */};
1271712717
T value;
12718-
for(const T item : vec){
12719-
if(/* some condition*/){
12718+
for (const T item : vec) {
12719+
if (/* some condition*/) {
1272012720
value = item;
1272112721
break;
1272212722
}
@@ -12725,30 +12725,30 @@ Often, a loop that requires a `break` is a good candidate for a function (algori
1272512725
}
1272612726

1272712727
//BETTER: create a function and return inside loop
12728-
T search(const std::vector<T> &vec){
12729-
for(const T &item : vec){
12730-
if(/* some condition*/) return item;
12728+
T search(const std::vector<T> &vec) {
12729+
for (const T &item : vec) {
12730+
if (/* some condition*/) return item;
1273112731
}
1273212732
return T(); //default value
1273312733
}
1273412734

12735-
void use2(){
12735+
void use2() {
1273612736
std::vector<T> vec = {/* initialized with some values */};
1273712737
T value = search(vec);
1273812738
/* then do something with value */
1273912739
}
1274012740

1274112741
Often, a loop that uses `continue` can equivalently and as clearly be expressed by an `if`-statement.
1274212742

12743-
for(int item : vec){ //BAD
12744-
if(item%2 == 0) continue;
12745-
if(item == 5) continue;
12746-
if(item > 10) continue;
12743+
for (int item : vec) { //BAD
12744+
if (item%2 == 0) continue;
12745+
if (item == 5) continue;
12746+
if (item > 10) continue;
1274712747
/* do something with item */
1274812748
}
1274912749

12750-
for(int item : vec){ //GOOD
12751-
if(item%2 != 0 && item != 5 && item <= 10){
12750+
for (int item : vec) { //GOOD
12751+
if (item%2 != 0 && item != 5 && item <= 10) {
1275212752
/* do something with item */
1275312753
}
1275412754
}
@@ -14972,21 +14972,20 @@ There is no explicit locking and both correct (value) return and error (exceptio
1497214972
return value;
1497314973
}
1497414974

14975-
1497614975
void async_example()
1497714976
{
1497814977
try
1497914978
{
14980-
auto v1 = std::async(std::launch::async, read_value, "v1.txt");
14979+
auto v1 = std::async(std::launch::async, read_value, "v1.txt");
1498114980
auto v2 = std::async(std::launch::async, read_value, "v2.txt");
1498214981
std::cout << v1.get() + v2.get() << '\n';
1498314982
}
14984-
catch (std::ios_base::failure & fail)
14983+
catch (std::ios_base::failure & fail)
1498514984
{
1498614985
// handle exception here
1498714986
}
1498814987
}
14989-
14988+
1499014989
##### Note
1499114990

1499214991
Unfortunately, `async()` is not perfect.
@@ -19200,6 +19199,7 @@ Nevertheless, the guidance is to use the quoted form for including files that ex
1920019199
#include "foo_utils/utils.h" // A file locally relative to foo.cpp, use "" form
1920119200

1920219201
##### Note
19202+
1920319203
Failing to follow this results in difficult to diagnose errors due to picking up the wrong file by incorrectly specifying the scope when it is included. For example, in a typical case where the `#include ""` search algorithm may search for a file existing at a local relative path first, then using this form to refer to a file that is not locally relative could mean that if a file ever comes into existence at the local relative path (e.g. the including file is moved to a new location), it will now be found ahead of the previous include file and the set of includes will have been changed in an unexpected way.
1920419204

1920519205
Library creators should put their headers in a folder and have clients include those files using the relative path `#include <some_library/common.h>`
@@ -20281,9 +20281,11 @@ and errors (when we didn't deal correctly with semi-constructed objects consiste
2028120281
// main problem: constructor does not fully construct
2028220282
Picture(int x, int y)
2028320283
{
20284-
mx = x; // also bad: assignment in constructor body rather than in member initializer
20284+
mx = x; // also bad: assignment in constructor body
20285+
// rather than in member initializer
2028520286
my = y;
20286-
data = nullptr; // also bad: constant initialization in constructor rather than in member initializer
20287+
data = nullptr; // also bad: constant initialization in constructor
20288+
// rather than in member initializer
2028720289
}
2028820290

2028920291
~Picture()
@@ -20465,7 +20467,7 @@ Reference sections:
2046520467
Libraries used have to have been approved for mission critical applications.
2046620468
Any similarities to this set of guidelines are unsurprising because Bjarne Stroustrup was an author of JSF++.
2046720469
Recommended, but note its very specific focus.
20468-
* [_MISRA C++ 2008: Guidelines for the use of the C++ language in critical systems_] (https://www.misra.org.uk/Buyonline/tabid/58/Default.aspx).
20470+
* [MISRA C++ 2008: Guidelines for the use of the C++ language in critical systems](https://www.misra.org.uk/Buyonline/tabid/58/Default.aspx).
2046920471
* [Mozilla Portability Guide](https://developer.mozilla.org/en-US/docs/Mozilla/C%2B%2B_Portability_Guide).
2047020472
As the name indicates, this aims for portability across many (old) compilers.
2047120473
As such, it is restrictive.

scripts/hunspell/isocpp.dic

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ ASIC
5252
asio
5353
AST
5454
async
55+
AUTOSAR
5556
'B'
5657
b2
5758
BDE
@@ -320,6 +321,7 @@ Meyers96
320321
Meyers97
321322
microbenchmarks
322323
middleware
324+
MISRA
323325
mixin
324326
mixins
325327
mnemonizes
@@ -598,6 +600,7 @@ UTF
598600
util
599601
v's
600602
v1
603+
v17
601604
v2
602605
va
603606
ValueType

0 commit comments

Comments
 (0)