Skip to content

Commit

Permalink
Modify rule S2808: add diff view and documentation link
Browse files Browse the repository at this point in the history
  • Loading branch information
amelie-renard-sonarsource committed Oct 9, 2023
1 parent 60713ff commit bf4d80d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions rules/S2808/cfamily/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
== Why is this an issue?

The ``++delete++`` operator expects a pointer argument. Passing it an object may compile and seem to run (with an implicit cast to pointer type) but it can result in unexpected behavior at runtime.
The ``++delete++`` operator expects a pointer argument. Passing an object to it may compile and seem to run (with an implicit cast to pointer type), but it can result in unexpected behavior at runtime.


=== Noncompliant code example

[source,cpp]
[source,cpp,diff-id=1,diff-type=noncompliant]
----
class CString {
public:
Expand All @@ -23,15 +23,24 @@ void fun() {

=== Compliant solution

[source,cpp]
[source,cpp,diff-id=1,diff-type=compliant]
----
class CString {
public:
operator const char*();
// ...
};
void fun() {
CString *pstr = new CString;
// ...
delete pstr;
}
----

== Resources

* {cpp} reference - https://en.cppreference.com/w/cpp/memory/new/operator_delete[operator delete]

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

Expand Down

0 comments on commit bf4d80d

Please sign in to comment.