Skip to content

Commit 51985b9

Browse files
Give code examples for when copy operations masquerade as moves.
1 parent 2813136 commit 51985b9

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

cpp/misra/src/rules/RULE-15-0-1/AnalyzableClass.qll

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,23 @@ private predicate implicitMoveIsSuppressed(Class c) {
6464
/**
6565
* Returns the move constructor of the class `c` if it exists, or the copy constructor if it does
6666
* not exist and the implicit definition was suppressed by the compiler.
67+
*
68+
* For example:
69+
* ```cpp
70+
* class OnlyCopyCtor {
71+
* public:
72+
* OnlyCopyCtor(const OnlyCopyCtor &) = default;
73+
* };
74+
*
75+
* static_assert(std::is_copy_constructible_v<OnlyCopyCtor>); // Succeeds
76+
* static_assert(std::is_move_constructible_v<OnlyCopyCtor>); // Also succeeds
77+
* ```
78+
*
79+
* Note that without the declared copy constructor, the compiler may define an implicit move
80+
* constructor.
81+
*
82+
* Additionally note that if the move constructor was declared as `= delete;`, then the second
83+
* assertion in the above example would fail.
6784
*/
6885
private Constructor getMoveConstructor(Class c) {
6986
if
@@ -76,6 +93,23 @@ private Constructor getMoveConstructor(Class c) {
7693
/**
7794
* Returns the move assignment operator of the class `c` if it exists, or the copy assignment
7895
* operator if it does not exist and the implicit definition was suppressed by the compiler.
96+
*
97+
* For example:
98+
* ```cpp
99+
* class OnlyCopyAssign {
100+
* public:
101+
* OnlyCopyAssign& operator=(const OnlyCopyAssign &) = default;
102+
* };
103+
*
104+
* static_assert(std::is_copy_assignable_v<OnlyCopyAssign>); // Succeeds
105+
* static_assert(std::is_move_assignable_v<OnlyCopyAssign>); // Also succeeds
106+
* ```
107+
*
108+
* Note that without the declared copy assignment operator, the compiler may define an implicit move
109+
* assignment operator.
110+
*
111+
* Additionally note that if the move assignment operator was declared as `= delete;`, then the second
112+
* assertion in the above example would fail.
79113
*/
80114
private Operator getMoveAssign(Class c) {
81115
if

0 commit comments

Comments
 (0)