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