mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2025-12-17 12:44:42 +03:00
Merge pull request #174 from tkruse/fix-mdstyle3
Fix minor style issues around bullet lists and Enforcement sections
This commit is contained in:
@@ -1764,7 +1764,6 @@ How big is a screen? Try 60 lines by 140 characters; that's roughly the maximum
|
|||||||
* Flag functions that are too complex. How complex is too complex?
|
* Flag functions that are too complex. How complex is too complex?
|
||||||
You could use cyclomatic complexity. Try "more that 10 logical path through." Count a simple switch as one path.
|
You could use cyclomatic complexity. Try "more that 10 logical path through." Count a simple switch as one path.
|
||||||
|
|
||||||
|
|
||||||
<a name="Rf-constexpr"></a>
|
<a name="Rf-constexpr"></a>
|
||||||
### F.4: If a function may have to be evaluated at compile time, declare it `constexpr`
|
### F.4: If a function may have to be evaluated at compile time, declare it `constexpr`
|
||||||
|
|
||||||
@@ -2124,7 +2123,6 @@ If you need the notion of an optional value, use a pointer, `std::optional`, or
|
|||||||
* (Simple) ((Foundation)) Warn when a parameter being passed by value has a size greater than `4*sizeof(int)`.
|
* (Simple) ((Foundation)) Warn when a parameter being passed by value has a size greater than `4*sizeof(int)`.
|
||||||
Suggest using a `const` reference instead.
|
Suggest using a `const` reference instead.
|
||||||
|
|
||||||
|
|
||||||
<a name="Rf-T"></a>
|
<a name="Rf-T"></a>
|
||||||
### F.21: Use a `T` parameter for a small object
|
### F.21: Use a `T` parameter for a small object
|
||||||
|
|
||||||
@@ -2351,7 +2349,6 @@ rather than using the generic `tuple`.
|
|||||||
* Output parameters should be replaced by return values.
|
* Output parameters should be replaced by return values.
|
||||||
An output parameter is one that the function writes to, invokes a non-`const` member function, or passes on as a non-`const`.
|
An output parameter is one that the function writes to, invokes a non-`const` member function, or passes on as a non-`const`.
|
||||||
|
|
||||||
|
|
||||||
<a name="Rf-return-ptr"></a>
|
<a name="Rf-return-ptr"></a>
|
||||||
### F.42: Return a `T*` to indicate a position (only)
|
### F.42: Return a `T*` to indicate a position (only)
|
||||||
|
|
||||||
@@ -3170,7 +3167,6 @@ Here `p` refers to `pp` but does not own it.
|
|||||||
* (Hard) Determine if pointer or reference member variables are owners when there is no explicit statement of ownership
|
* (Hard) Determine if pointer or reference member variables are owners when there is no explicit statement of ownership
|
||||||
(e.g., look into the constructors).
|
(e.g., look into the constructors).
|
||||||
|
|
||||||
|
|
||||||
<a name="Rc-dtor-ptr"></a>
|
<a name="Rc-dtor-ptr"></a>
|
||||||
### C.32: If a class has a raw pointer (`T*`) or reference (`T&`), consider whether it might be owning
|
### C.32: If a class has a raw pointer (`T*`) or reference (`T&`), consider whether it might be owning
|
||||||
|
|
||||||
@@ -4019,7 +4015,6 @@ See [copy constructor vs. `clone()`](#Rc-copy-virtual).
|
|||||||
* (Moderate) An assignment operator should (implicitly or explicitly) invoke all base and member assignment operators.
|
* (Moderate) An assignment operator should (implicitly or explicitly) invoke all base and member assignment operators.
|
||||||
Look at the destructor to determine if the type has pointer semantics or value semantics.
|
Look at the destructor to determine if the type has pointer semantics or value semantics.
|
||||||
|
|
||||||
|
|
||||||
<a name="Rc-copy-semantic"></a>
|
<a name="Rc-copy-semantic"></a>
|
||||||
### C.61: A copy operation should copy
|
### C.61: A copy operation should copy
|
||||||
|
|
||||||
@@ -5490,7 +5485,7 @@ the optimal strategy (for performance and ease of programming) is sometimes simp
|
|||||||
If you have enough memory to handle your largest input, leak away, but be sure to give a good error message if you are wrong.
|
If you have enough memory to handle your largest input, leak away, but be sure to give a good error message if you are wrong.
|
||||||
Here, we ignore such cases.
|
Here, we ignore such cases.
|
||||||
|
|
||||||
Resource management rule summary:
|
* Resource management rule summary:
|
||||||
|
|
||||||
* [R.1: Manage resources automatically using resource handles and RAII (resource acquisition is initialization)](#Rr-raii)
|
* [R.1: Manage resources automatically using resource handles and RAII (resource acquisition is initialization)](#Rr-raii)
|
||||||
* [R.2: In interfaces, use raw pointers to denote individual objects (only)](#Rr-use-ptr)
|
* [R.2: In interfaces, use raw pointers to denote individual objects (only)](#Rr-use-ptr)
|
||||||
@@ -5499,7 +5494,7 @@ Resource management rule summary:
|
|||||||
* [R.5: Prefer scoped objects](#Rr-scoped)
|
* [R.5: Prefer scoped objects](#Rr-scoped)
|
||||||
* [R.6: Avoid non-`const` global variables](#Rr-global)
|
* [R.6: Avoid non-`const` global variables](#Rr-global)
|
||||||
|
|
||||||
Alocation and deallocation rule summary:
|
* Alocation and deallocation rule summary:
|
||||||
|
|
||||||
* [R.10: Avoid `malloc()` and `free()`](#Rr-mallocfree)
|
* [R.10: Avoid `malloc()` and `free()`](#Rr-mallocfree)
|
||||||
* [R.11: Avoid calling `new` and `delete` explicitly](#Rr-newdelete)
|
* [R.11: Avoid calling `new` and `delete` explicitly](#Rr-newdelete)
|
||||||
@@ -5508,8 +5503,7 @@ Alocation and deallocation rule summary:
|
|||||||
* [R.14: ??? array vs. pointer parameter](#Rr-ap)
|
* [R.14: ??? array vs. pointer parameter](#Rr-ap)
|
||||||
* [R.15: Always overload matched allocation/deallocation pairs](#Rr-pair)
|
* [R.15: Always overload matched allocation/deallocation pairs](#Rr-pair)
|
||||||
|
|
||||||
<a name ="Rr-summary-smartptrs"></a>Smart pointer rule summary:
|
* <a name ="Rr-summary-smartptrs"></a>Smart pointer rule summary:
|
||||||
|
|
||||||
* [R.20: Use `unique_ptr` or `shared_ptr` to represent ownership](#Rr-owner)
|
* [R.20: Use `unique_ptr` or `shared_ptr` to represent ownership](#Rr-owner)
|
||||||
* [R.21: Prefer `unique_ptr` over `shared_ptr` unless you need to share ownership](#Rr-unique)
|
* [R.21: Prefer `unique_ptr` over `shared_ptr` unless you need to share ownership](#Rr-unique)
|
||||||
* [R.22: Use `make_shared()` to make `shared_ptr`s](#Rr-make_shared)
|
* [R.22: Use `make_shared()` to make `shared_ptr`s](#Rr-make_shared)
|
||||||
@@ -5524,7 +5518,6 @@ Alocation and deallocation rule summary:
|
|||||||
* [R.36: Take a `const shared_ptr<widget>&` parameter to express that it might retain a reference count to the object ???](#Rr-sharedptrparam-const&)
|
* [R.36: Take a `const shared_ptr<widget>&` parameter to express that it might retain a reference count to the object ???](#Rr-sharedptrparam-const&)
|
||||||
* [R.37: Do not pass a pointer or reference obtained from an aliased smart pointer](#Rr-smartptrget)
|
* [R.37: Do not pass a pointer or reference obtained from an aliased smart pointer](#Rr-smartptrget)
|
||||||
|
|
||||||
|
|
||||||
<a name ="Rr-raii"></a>
|
<a name ="Rr-raii"></a>
|
||||||
### Rule R.1: Manage resources automatically using resource handles and RAII (resource acquisition is initialization)
|
### Rule R.1: Manage resources automatically using resource handles and RAII (resource acquisition is initialization)
|
||||||
|
|
||||||
@@ -5706,7 +5699,6 @@ return a "smart pointer."
|
|||||||
* (Simple) Warn if a function returns an object that was allocated within the function but has a move constructor.
|
* (Simple) Warn if a function returns an object that was allocated within the function but has a move constructor.
|
||||||
Suggest considering returning it by value instead.
|
Suggest considering returning it by value instead.
|
||||||
|
|
||||||
|
|
||||||
<a name="Rr-ref"></a>
|
<a name="Rr-ref"></a>
|
||||||
### R.4: A raw reference (a `T&`) is non-owning
|
### R.4: A raw reference (a `T&`) is non-owning
|
||||||
|
|
||||||
@@ -6073,7 +6065,6 @@ A function that does not manipulate lifetime should take raw pointers or referen
|
|||||||
* (Simple) Warn if a function takes a parameter of a type that is a `Unique_ptr` or `Shared_ptr` and the function only calls any of: `operator*`, `operator->` or `get()`).
|
* (Simple) Warn if a function takes a parameter of a type that is a `Unique_ptr` or `Shared_ptr` and the function only calls any of: `operator*`, `operator->` or `get()`).
|
||||||
Suggest using a `T*` or `T&` instead.
|
Suggest using a `T*` or `T&` instead.
|
||||||
|
|
||||||
|
|
||||||
<a name="Rr-smart"></a>
|
<a name="Rr-smart"></a>
|
||||||
### R.31: If you have non-`std` smart pointers, follow the basic pattern from `std`
|
### R.31: If you have non-`std` smart pointers, follow the basic pattern from `std`
|
||||||
|
|
||||||
@@ -7030,7 +7021,7 @@ If at all possible, reduce the conditions to a simple set of alternatives (e.g.,
|
|||||||
case file: owned=true; return *new ifstream{argv[2]};
|
case file: owned=true; return *new ifstream{argv[2]};
|
||||||
}();
|
}();
|
||||||
|
|
||||||
**Enforcement:** Hard. At best a heuristic. Look for an unitialized variable followed by a loop assigning to it.
|
**Enforcement**: Hard. At best a heuristic. Look for an unitialized variable followed by a loop assigning to it.
|
||||||
|
|
||||||
|
|
||||||
<a name="Res-macros"></a>
|
<a name="Res-macros"></a>
|
||||||
@@ -11007,9 +10998,9 @@ Before a variable has been initialized, it does not contain a deterministic vali
|
|||||||
use(x2);
|
use(x2);
|
||||||
|
|
||||||
**Enforcement**:
|
**Enforcement**:
|
||||||
- Issue a diagnostic for any constructor of a non-trivially-constructible type that does not initialize all member variables. To fix: Write a data member initializer, or mention it in the member initializer list.
|
|
||||||
- Issue a diagnostic when constructing an object of a trivially constructible type without `()` or `{}` to initialize its members. To fix: Add `()` or `{}`.
|
|
||||||
|
|
||||||
|
* Issue a diagnostic for any constructor of a non-trivially-constructible type that does not initialize all member variables. To fix: Write a data member initializer, or mention it in the member initializer list.
|
||||||
|
* Issue a diagnostic when constructing an object of a trivially constructible type without `()` or `{}` to initialize its members. To fix: Add `()` or `{}`.
|
||||||
|
|
||||||
<a name="Pro-type-unions"></a>
|
<a name="Pro-type-unions"></a>
|
||||||
### Type.7: Avoid accessing members of raw unions. Prefer `variant` instead.
|
### Type.7: Avoid accessing members of raw unions. Prefer `variant` instead.
|
||||||
@@ -11033,9 +11024,8 @@ Reading from a union member assumes that member was the last one written, and wr
|
|||||||
Note that just copying a union is not type-unsafe, so safe code can pass a union from one piece of unsafe code to another.
|
Note that just copying a union is not type-unsafe, so safe code can pass a union from one piece of unsafe code to another.
|
||||||
|
|
||||||
**Enforcement**:
|
**Enforcement**:
|
||||||
- Issue a diagnostic for accessing a member of a union. To fix: Use a `variant` instead.
|
|
||||||
|
|
||||||
|
|
||||||
|
* Issue a diagnostic for accessing a member of a union. To fix: Use a `variant` instead.
|
||||||
|
|
||||||
<a name="Pro-type-varargs"></a>
|
<a name="Pro-type-varargs"></a>
|
||||||
### Type.8: Avoid reading from varargs or passing vararg arguments. Prefer variadic template parameters instead.
|
### Type.8: Avoid reading from varargs or passing vararg arguments. Prefer variadic template parameters instead.
|
||||||
@@ -11066,10 +11056,9 @@ Reading from a vararg assumes that the correct type was actually passed. Passing
|
|||||||
Note: Declaring a `...` parameter is sometimes useful for techniques that don't involve actual argument passing, notably to declare “take-anything” functions so as to disable "everything else" in an overload set or express a catchall case in a template metaprogram.
|
Note: Declaring a `...` parameter is sometimes useful for techniques that don't involve actual argument passing, notably to declare “take-anything” functions so as to disable "everything else" in an overload set or express a catchall case in a template metaprogram.
|
||||||
|
|
||||||
**Enforcement**:
|
**Enforcement**:
|
||||||
- Issue a diagnostic for using `va_list`, `va_start`, or `va_arg`. To fix: Use a variadic template parameter list instead.
|
|
||||||
- Issue a diagnostic for passing an argument to a vararg parameter. To fix: Use a different function, or `[[suppress(types)]]`.
|
|
||||||
|
|
||||||
|
|
||||||
|
* Issue a diagnostic for using `va_list`, `va_start`, or `va_arg`. To fix: Use a variadic template parameter list instead.
|
||||||
|
* Issue a diagnostic for passing an argument to a vararg parameter. To fix: Use a different function, or `[[suppress(types)]]`.
|
||||||
|
|
||||||
<a name="SS-bounds"></a>
|
<a name="SS-bounds"></a>
|
||||||
## Bounds safety profile
|
## Bounds safety profile
|
||||||
@@ -11298,15 +11287,14 @@ These functions all have bounds-safe overloads that take `array_view`. Standard
|
|||||||
}
|
}
|
||||||
|
|
||||||
**Enforcement**:
|
**Enforcement**:
|
||||||
- Issue a diagnostic for any call to a standard library function that is not bounds-checked. ??? insert link to a list of banned functions
|
|
||||||
|
* Issue a diagnostic for any call to a standard library function that is not bounds-checked. ??? insert link to a list of banned functions
|
||||||
|
|
||||||
**TODO Notes**:
|
**TODO Notes**:
|
||||||
- Impact on the standard library will require close coordination with WG21, if only to ensure compatibility even if never standardized.
|
|
||||||
- We are considering specifying bounds-safe overloads for stdlib (especially C stdlib) functions like `memcmp` and shipping them in the GSL.
|
|
||||||
- For existing stdlib functions and types like `vector` that are not fully bounds-checked, the goal is for these features to be bounds-checked when called from code with the bounds profile on, and unchecked when called from legacy code, possibly using constracts (concurrently being proposed by several WG21 members).
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
* Impact on the standard library will require close coordination with WG21, if only to ensure compatibility even if never standardized.
|
||||||
|
* We are considering specifying bounds-safe overloads for stdlib (especially C stdlib) functions like `memcmp` and shipping them in the GSL.
|
||||||
|
* For existing stdlib functions and types like `vector` that are not fully bounds-checked, the goal is for these features to be bounds-checked when called from code with the bounds profile on, and unchecked when called from legacy code, possibly using constracts (concurrently being proposed by several WG21 members).
|
||||||
|
|
||||||
<a name="SS-lifetime"></a>
|
<a name="SS-lifetime"></a>
|
||||||
## Lifetime safety profile
|
## Lifetime safety profile
|
||||||
@@ -11399,7 +11387,6 @@ Use `not_null<zstring>` for C-style strings that cannot be `nullptr`. ??? Do we
|
|||||||
* `dyn_array<T>` // ??? needed ??? A heap-allocated array. The number of elements are determined at construction and fixed thereafter.
|
* `dyn_array<T>` // ??? needed ??? A heap-allocated array. The number of elements are determined at construction and fixed thereafter.
|
||||||
The elements are mutable unless `T` is a `const` type. Basically an `array_view` that allocates and owns its elements.
|
The elements are mutable unless `T` is a `const` type. Basically an `array_view` that allocates and owns its elements.
|
||||||
|
|
||||||
|
|
||||||
<a name="SS-assertions"></a>
|
<a name="SS-assertions"></a>
|
||||||
## GSL.assert: Assertions
|
## GSL.assert: Assertions
|
||||||
|
|
||||||
@@ -11531,7 +11518,7 @@ Comments are not updated as consistently as code.
|
|||||||
if (i==j)
|
if (i==j)
|
||||||
return i;
|
return i;
|
||||||
|
|
||||||
Enforcement: Use a tool.
|
**Enforcement**: Use a tool.
|
||||||
|
|
||||||
|
|
||||||
<a name="Rl-name-type"></a>
|
<a name="Rl-name-type"></a>
|
||||||
|
|||||||
Reference in New Issue
Block a user