Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

48 lines
1.5 KiB
Plaintext

== Why is this an issue?
Functions that deal with iterators often use the notion of range: A range is a pair or iterators, ``++b++`` and ``++e++``, with the following conditions:
* ``++b++`` and ``++e++`` must refer to the same container
* ``++e++`` must be reachable from ``++b++``, which mean that by doing ``b{plus}{plus}`` enough times, we must reach ``++e++`` (another way to say it is that ``++b++`` must be before ``++e++`` in the container).
An invalid range will most of the time lead to undefined behavior.
This rule detects when two iterators that do not make a valid range are passed to a function that expects a range.
=== Noncompliant code example
[source,cpp]
----
void test(std::vector<int> &v1, std::vector<int> &v2) {
// First argument is the insert position, second and third arguments are the range to insert
v1.insert(v1.begin(), v1.begin(), v2.end()); // Noncompliant, not in the same container
std::sort(v1.end(), v1.begin()); // Noncompliant, the two parameters need to be swapped to define a valid range
}
----
=== Compliant solution
[source,cpp]
----
void test(std::vector<int> &v1, std::vector<int> &v2) {
v1.insert(v1.begin(), v2.begin(), v2.end()); // Compliant
std::sort(v1.begin(), v1.end()); // Compliant
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
iterators of different containers used where the same container is expected
endif::env-github,rspecator-view[]