Skip to content

Commit

Permalink
Modify rule S5950: Move exception code example and update links
Browse files Browse the repository at this point in the history
  • Loading branch information
amelie-renard-sonarsource committed Sep 28, 2023
1 parent e5b3e07 commit b965af0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions rules/S5950/cfamily/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ std::shared_ptr<MyClass> sharedP(new MyClass(42)); // Noncompliant
----
auto uniqueP = std::make_unique<MyClass>(42);
auto sharedP = std::make_shared<MyClass>(42);
std::unique_ptr<std::FILE, std::function<void(std::FILE*)>> file(
fopen("example.txt", "r"),
[](FILE* inFile) { fclose(inFile); }); // Compliant: custom deleter is specified
----


Expand All @@ -57,6 +54,14 @@ std::unique_ptr<std::FILE, std::function<void(std::FILE*)>> file(
This rule ignores code that uses features not supported by `make_shared` and `make_unique`:

* custom deleters

[source,cpp]
----
std::unique_ptr<std::FILE, std::function<void(std::FILE*)>> file(
fopen("example.txt", "r"),
[](FILE* inFile) { fclose(inFile); }); // Compliant: custom deleter is specified
----

* calling placement-new, i.e., version of `new` with arguments, like `new(std::nothrow)`

In addition, `make_shared` does not support the following:
Expand All @@ -66,8 +71,8 @@ In addition, `make_shared` does not support the following:

== Resources

* https://github.com/isocpp/CppCoreGuidelines/blob/c553535fb8dda2839d13ab5f807ffbc66b63d67b/CppCoreGuidelines.md#c150-use-make_unique-to-construct-objects-owned-by-unique_ptrs[{cpp} Core Guidelines C.150] - Use make_unique() to construct objects owned by unique_ptrs
* https://github.com/isocpp/CppCoreGuidelines/blob/c553535fb8dda2839d13ab5f807ffbc66b63d67b/CppCoreGuidelines.md#c151-use-make_shared-to-construct-objects-owned-by-shared_ptrs[{cpp} Core Guidelines C.151] - Use make_shared() to construct objects owned by shared_ptrs
* {cpp] Core Guidelines - https://github.com/isocpp/CppCoreGuidelines/blob/036324/CppCoreGuidelines.md#c150-use-make_unique-to-construct-objects-owned-by-unique_ptrs[C.150 - Use make_unique() to construct objects owned by unique_ptrs]
* {cpp] Core Guidelines - https://github.com/isocpp/CppCoreGuidelines/blob/036324/CppCoreGuidelines.md#c151-use-make_shared-to-construct-objects-owned-by-shared_ptrs[C.151 - Use make_shared() to construct objects owned by shared_ptrs]

ifdef::env-github,rspecator-view[]

Expand Down

0 comments on commit b965af0

Please sign in to comment.