C++ CPA common mistakes
C++ CPA · Understand the traps and how to avoid them.
Using operator precedence as if it guaranteed every side-effect evaluation order.
The simplified claim overlooks a distinct language contract, object or operation that determines validity and result.
What to do instead
Check the actual sequencing rule and language version separately from grouping.
Converting an integer-division result and expecting it to recover the discarded fraction.
The simplified claim overlooks a distinct language contract, object or operation that determines validity and result.
What to do instead
Convert an appropriate operand before division when the required operation is floating point.
Deleting through a base pointer merely because another member function is virtual.
The simplified claim overlooks a distinct language contract, object or operation that determines validity and result.
What to do instead
Check the actual ownership and virtual-destructor requirements for that deletion.
Equating a retained address with a live dereferenceable object.
The simplified claim overlooks a distinct language contract, object or operation that determines validity and result.
What to do instead
Track lifetime, ownership and allowed array bounds before pointer use.
Treating reserve as resize or assuming its resulting capacity is exactly requested.
The simplified claim overlooks a distinct language contract, object or operation that determines validity and result.
What to do instead
Separate unchanged size from the guaranteed minimum capacity and supported element creation.
Expecting remove or unique alone to shrink a container.
The simplified claim overlooks a distinct language contract, object or operation that determines validity and result.
What to do instead
Use the returned logical end with the appropriate erase operation when actual removal is intended.
Saying std::move itself moved a resource or universally emptied the source.
The simplified claim overlooks a distinct language contract, object or operation that determines validity and result.
What to do instead
Follow overload selection and the actual type’s operation/postconditions.
Assuming every output manipulator has identical persistence.
The simplified claim overlooks a distinct language contract, object or operation that determines validity and result.
What to do instead
Trace the actual stream flag or next-insertion width contract.