mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
fix unnecessary block
This commit is contained in:
parent
6a39a88bf8
commit
2db47928df
|
@ -3436,25 +3436,21 @@ Pointers and references to locals shouldn't outlive their scope. Lambdas that ca
|
|||
|
||||
##### Example, bad
|
||||
|
||||
{
|
||||
int local = 42;
|
||||
int local = 42;
|
||||
|
||||
// Want a reference to local.
|
||||
// Note, that after program exits this scope,
|
||||
// local no longer exists, therefore
|
||||
// process() call will have undefined behavior!
|
||||
thread_pool.queue_work([&]{ process(local); });
|
||||
}
|
||||
// Want a reference to local.
|
||||
// Note, that after program exits this scope,
|
||||
// local no longer exists, therefore
|
||||
// process() call will have undefined behavior!
|
||||
thread_pool.queue_work([&]{ process(local); });
|
||||
|
||||
##### Example, good
|
||||
|
||||
{
|
||||
int local = 42;
|
||||
// Want a copy of local.
|
||||
// Since a copy of local is made, it will be
|
||||
// available at all times for the call.
|
||||
thread_pool.queue_work([=]{ process(local); });
|
||||
}
|
||||
int local = 42;
|
||||
// Want a copy of local.
|
||||
// Since a copy of local is made, it will be
|
||||
// available at all times for the call.
|
||||
thread_pool.queue_work([=]{ process(local); });
|
||||
|
||||
##### Enforcement
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user