Fred Tingaud 22b4470f2a
Modify CFamily rules: CPP-4080 Refresh and standardize CppCoreGuidelines references (#3514)
Update all links to C++ Core Guidelines to `e49158a`.

Refresh done using the following script and some manual edits:
db76e34e74/personal/fred-tingaud/rspec/refresh-cppcoreguidelines.py

When re-using this script, be mindful that:
 - it does not cover `shared_content`
 - it does not properly escape inline code in links (e.g., "[=]" or "`mutex`es")
 - it does not change `C++` to `{cpp}` in link titles.

Co-authored-by: Marco Borgeaud <marco.borgeaud@sonarsource.com>
2023-12-20 10:08:18 +01:00

55 lines
1.3 KiB
Plaintext

== Why is this an issue?
The RAII idiom associates the lifetime of a resource with the lifetime of an object: The resource is acquired when the object is created, and released when it is destroyed.
If the object that controls the resource lifetime is a temporary, chances are it will get destroyed while the resource should still be in use, leading to resource corruption. This rule detects temporaries that look like RAII objects.
=== Noncompliant code example
[source,cpp]
----
void f() {
scoped_lock{myMutex}; // Noncompliant. The mutex will be locked then immediately unlocked
protectedCode(); // This code is not protected by the mutex
}
----
=== Compliant solution
[source,cpp]
----
void f() {
scoped_lock lock{myMutex}; // Compliant
protectedCode();
// The mutex is correctly released at this point
}
----
== Resources
* {cpp} Core Guidelines - https://github.com/isocpp/CppCoreGuidelines/blob/e49158a/CppCoreGuidelines.md#es84-dont-try-to-declare-a-local-variable-with-no-name[ES.84: Don't try to declare a local variable with no name]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Name this temporary XXX object if you want to use it in for RAII.
'''
== Comments And Links
(visible only on this page)
=== is related to: S5506
endif::env-github,rspecator-view[]