Skip to content

Commit 0ece1d9

Browse files
hsutterbeinhaerter
andauthored
Apply suggestions from code review
Co-authored-by: Werner Henze <34543625+beinhaerter@users.noreply.github.com>
1 parent 0de9771 commit 0ece1d9

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

CppCoreGuidelines.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4812,15 +4812,15 @@ If data member `B` uses another data member `A`, then `A` must be declared befor
48124812
class X {
48134813
struct B {
48144814
string* p;
4815-
explicit B(string& a) : p(&a) {}
4815+
explicit B(string& a) : p{&a} {}
48164816
~B() { cout << *p; } // uses a (via p)
48174817
};
48184818

48194819
B b; // constructed first
48204820
string a = "some heap allocated string value"; // constructed after b; destroyed before b
48214821

48224822
public:
4823-
X() : b(a) {} // uses a before it is constructed -> use-before-alloc UB
4823+
X() : b{a} {} // uses a before it is constructed -> use-before-alloc UB
48244824
~X() = default; // accesses a after it is destroyed -> use-after-free UB
48254825
};
48264826

@@ -4831,26 +4831,26 @@ If data member `B` uses another data member `A`, then `A` must be declared befor
48314831
class X {
48324832
struct B {
48334833
string* p;
4834-
explicit B(string& a) : p(&a) {}
4834+
explicit B(string& a) : p{&a} {}
48354835
~B() { cout << *p; } // uses a (via p)
48364836
};
48374837

48384838
string a = "some heap allocated string value"; // constructed before b; destroyed after b
48394839
B b; // constructed second
48404840

48414841
public:
4842-
X() : b(a) {} // ok
4842+
X() : b{a} {} // ok
48434843
~X() = default; // ok
48444844
};
48454845

48464846
##### Example; bad
48474847

4848-
This can also come up with concurrency. Ensure that an async operation that access a value is joined before the value it accesses is destroyed.
4848+
This can also come up with concurrency. Ensure that an async operation that accesses a value is joined before the value it accesses is destroyed.
48494849

48504850
class X {
48514851
public:
48524852
X()
4853-
: a(std::make_unique<int>(12))
4853+
: a{std::make_unique<int>(12)}
48544854
{
48554855
b = std::make_unique<std::jthread>(
48564856
[this]{
@@ -4865,7 +4865,7 @@ This can also come up with concurrency. Ensure that an async operation that acce
48654865

48664866
##### Example; good
48674867

4868-
This can also come up with concurrency. Ensure that an async operation that access a value is joined before the value it accesses is destroyed.
4868+
This can also come up with concurrency. Ensure that an async operation that accesses a value is joined before the value it accesses is destroyed.
48694869

48704870
// Corrected: Just declare a before b
48714871

0 commit comments

Comments
 (0)