unique_ptr::get() returns pointee addresses, not container iterators.
Comparing two owners' addresses is valid and can establish distinct ownership.
A copied floating-point value can be NaN. Both number <= copy and number >= copy are then false, so they cannot be classified as always true.
The strict comparisons are intentionally false controls in this example.
Overlay::SetText can change the child returned by Child(). Calling a
const getter through a retained child pointer does not freeze its value.
Actual
value-flow.cpp:6: error: Iterators of different containers 'first' and 'second' are used together. [mismatchingContainers]
value-flow.cpp:15: style: The comparison 'number <= copy' is always true because 'number' and 'copy' represent the same value. [knownConditionTrueFalse]
value-flow.cpp:16: style: The comparison 'number < copy' is always false because 'number' and 'copy' represent the same value. [knownConditionTrueFalse]
value-flow.cpp:17: style: The comparison 'number >= copy' is always true because 'number' and 'copy' represent the same value. [knownConditionTrueFalse]
value-flow.cpp:18: style: The comparison 'number > copy' is always false because 'number' and 'copy' represent the same value. [knownConditionTrueFalse]
value-flow.cpp:40: style: The comparison 'label->Height() > previous' is always false because 'label->Height()' and 'previous' represent the same value. [knownConditionTrueFalse]
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
https://trac.cppcheck.net/ticket/15158 tracks the mismatchingContainersmessage.
Having different smart pointers own the same resource is a bug waiting to happen, so I think showing a warning is desirable.
Other issues still open.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Repro
Save as
value-flow.cpp:Version:
Cppcheck 2.22.0(Linux).Expected
unique_ptr::get()returns pointee addresses, not container iterators.Comparing two owners' addresses is valid and can establish distinct ownership.
number <= copyandnumber >= copyare then false, so they cannot be classified as always true.The strict comparisons are intentionally false controls in this example.
Overlay::SetTextcan change the child returned byChild(). Calling aconst getter through a retained child pointer does not freeze its value.
Actual
https://trac.cppcheck.net/ticket/15158 tracks the
mismatchingContainersmessage.Having different smart pointers own the same resource is a bug waiting to happen, so I think showing a warning is desirable.
Other issues still open.
knownConditionTrueFalseis tracked here: https://trac.cppcheck.net/ticket/15171