2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-04-28 16:49:39 +02:00
By contract, chaining the 'Address of' operator ``++&++`` with the 'Indirection' operator ``++*++`` results in a return to the initial value. Thus, such combinations are confusing at best, and bugs at worst.
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,cpp]
2021-04-28 16:49:39 +02:00
----
int *ptr = ...;
int *result1 = &(*ptr); //Noncompliant
int *result2 = &*ptr; //Noncompliant
int value = 4;
int result3 = *(&value); //Noncompliant
int result4 = *&value; //Noncompliant
----
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,cpp]
2021-04-28 16:49:39 +02:00
----
int *ptr = ...;
int *result1 = ptr;
int *result2 = ptr;
int value = 4;
int result3 = value;
int result4 = value;
----
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
=== Exceptions
2021-04-28 16:49:39 +02:00
No issue is raised when the ``++*++`` or ``++&++`` operators are overloaded or when both operators are not located in the same piece of code (one being generated by a macro expansion and the other one located in the main source code for instance).
2021-04-28 18:08:03 +02:00
2021-06-02 20:44:38 +02:00
2021-06-03 09:05:38 +02:00
ifdef::env-github,rspecator-view[]
2021-09-20 15:38:42 +02:00
'''
== Implementation Specification
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== Message
Remove this useless sequence of pointer operators: "xxx".
=== Highlighting
The sequence of pointer operators
2021-09-20 15:38:42 +02:00
2021-06-08 15:52:13 +02:00
'''
2021-06-02 20:44:38 +02:00
== Comments And Links
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== relates to: S2761
=== on 19 Jan 2016, 11:08:48 Alban Auzeill wrote:
About the Labels: "bug"
I can't find one case where it can be a bug. In my view, it's more: brain-overload and perhaps performance
About "SQALE Characteristic": Reliability - Logic related reliability
In my view it's more: understandability or readability
2021-06-03 09:05:38 +02:00
endif::env-github,rspecator-view[]