mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2025-12-17 12:44:42 +03:00
fix unnecessary block
This commit is contained in:
@@ -3436,7 +3436,6 @@ Pointers and references to locals shouldn't outlive their scope. Lambdas that ca
|
|||||||
|
|
||||||
##### Example, bad
|
##### Example, bad
|
||||||
|
|
||||||
{
|
|
||||||
int local = 42;
|
int local = 42;
|
||||||
|
|
||||||
// Want a reference to local.
|
// Want a reference to local.
|
||||||
@@ -3444,17 +3443,14 @@ Pointers and references to locals shouldn't outlive their scope. Lambdas that ca
|
|||||||
// local no longer exists, therefore
|
// local no longer exists, therefore
|
||||||
// process() call will have undefined behavior!
|
// process() call will have undefined behavior!
|
||||||
thread_pool.queue_work([&]{ process(local); });
|
thread_pool.queue_work([&]{ process(local); });
|
||||||
}
|
|
||||||
|
|
||||||
##### Example, good
|
##### Example, good
|
||||||
|
|
||||||
{
|
|
||||||
int local = 42;
|
int local = 42;
|
||||||
// Want a copy of local.
|
// Want a copy of local.
|
||||||
// Since a copy of local is made, it will be
|
// Since a copy of local is made, it will be
|
||||||
// available at all times for the call.
|
// available at all times for the call.
|
||||||
thread_pool.queue_work([=]{ process(local); });
|
thread_pool.queue_work([=]{ process(local); });
|
||||||
}
|
|
||||||
|
|
||||||
##### Enforcement
|
##### Enforcement
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user