rspec/rules/S3491/rule.adoc

34 lines
851 B
Plaintext
Raw Normal View History

2021-01-27 13:42:22 +01: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.
2020-06-30 12:48:39 +02:00
== Noncompliant Code Example
----
int *ptr = ...;
int *result1 = &(*ptr); //Noncompliant
int *result2 = &*ptr; //Noncompliant
int value = 4;
int result3 = *(&value); //Noncompliant
int result4 = *&value; //Noncompliant
----
== Compliant Solution
----
int *ptr = ...;
int *result1 = ptr;
int *result2 = ptr;
int value = 4;
int result3 = value;
int result4 = value;
----
== Exceptions
2021-01-27 13:42:22 +01: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).
2020-06-30 12:48:39 +02:00