|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
The pattern test of the moved-from objects. More...
#include <concepts>#include <cstddef>#include <type_traits>#include <utility>#include <gtest/gtest.h>Go to the source code of this file.
Classes | |
| class | MovedFrom< T > |
| The typed suite of the moved-from tests. More... | |
Functions | |
| template<class Case , class T > | |
| auto | moved_from_fingerprint (const T &x) |
| What a move must carry from its source to its destination. | |
| TYPED_TEST_SUITE_P (MovedFrom) | |
| TYPED_TEST_P (MovedFrom, ConstructionLeavesAnEmptyUsableSource) | |
| TYPED_TEST_P (MovedFrom, AssignmentLeavesBothObjectsUsable) | |
| REGISTER_TYPED_TEST_SUITE_P (MovedFrom, ConstructionLeavesAnEmptyUsableSource, AssignmentLeavesBothObjectsUsable) | |
The pattern test of the moved-from objects.
A class that keeps a size or a parameter in a member of its own, beside the array that it describes, is left inconsistent by the implicit moves: they take the array, which is left empty in the source (or exchanged, in a move assignment), but copy the scalar. The moved-from object then reads or writes storage that it no longer has. These typed tests move from objects of each class given to them and use the sources and the destinations, so that a class with the pattern fails: with an exception or an assertion of a checked access, and under AddressSanitizer with a report of the unchecked accesses.
Each class is given by specializing Moved_From_Case for it, and the suite is instantiated with a list of them:
is_empty() may take the object as const or not.
use() must do what an ordinary user does with any object of the class, an empty one included: walk the positions that the object reports, read and write them, insert, query and clear. A use that only destroys or assigns the object does not show the pattern.
The destination of a move must have what the source had. The tests compare fingerprint() of the source before the move with that of the destination after it; a class without one is compared by its size(), if it has one. A move assignment may leave in the source the previous state of the destination (an exchange) or an empty object, so the tests do not compare the source after it.
Definition in file moved_from.H.
| auto moved_from_fingerprint | ( | const T & | x | ) |
What a move must carry from its source to its destination.
| Case | The Moved_From_Case of the class. |
| T | The class. |
| [in] | x | The object. |
Case::fingerprint(x) if the case gives one, else the size of x if it has one, else 0 (nothing to compare). Definition at line 102 of file moved_from.H.
| REGISTER_TYPED_TEST_SUITE_P | ( | MovedFrom | , |
| ConstructionLeavesAnEmptyUsableSource | , | ||
| AssignmentLeavesBothObjectsUsable | |||
| ) |
| TYPED_TEST_P | ( | MovedFrom | , |
| AssignmentLeavesBothObjectsUsable | |||
| ) |
Definition at line 138 of file moved_from.H.
References print().
| TYPED_TEST_P | ( | MovedFrom | , |
| ConstructionLeavesAnEmptyUsableSource | |||
| ) |
Definition at line 121 of file moved_from.H.
References print().
| TYPED_TEST_SUITE_P | ( | MovedFrom | ) |