GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Give code examples for when copy operations masquerade as moves. · github/codeql-coding-standards@51985b9

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • cpp/misra/src/rules/RULE-15-0-1
    • AnalyzableClass.qll
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: cpp/misra/src/rules/RULE-15-0-1/AnalyzableClass.qll
+34Lines 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 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.