Skip to content

Commit 61a4dd9

Browse files
Review feedback
1 parent 51985b9 commit 61a4dd9

5 files changed

Lines changed: 19 additions & 7 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private predicate isUserDeclared(MemberFunction f) { not f.isCompilerGenerated()
5151
* Holds if the implicit move constructor or move assignment operator of the class `c` will not be
5252
* declared.
5353
*
54-
* See [class.copy]/8 and [class.copy]
54+
* Specified in [class.copy.ctor]/8 and [class.copy.assign]/4.
5555
*/
5656
private predicate implicitMoveIsSuppressed(Class c) {
5757
isUserDeclared(c.getAConstructor().(CopyConstructor))

cpp/misra/src/rules/RULE-15-0-1/ImproperlyProvidedSpecialMemberFunctions.ql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,11 @@ predicate violatesCustomizedMoveOrCopyRequirements(AnalyzableClass c, string rea
8282
private predicate undeclaredMoveException(AnalyzableClass c) {
8383
// A copy-enabled class may have an undeclared move constructor.
8484
isCopyEnabled(c) and
85-
not c.moveAssignable() and
85+
not c.copyAssignable() and
8686
not c.declaresMoveConstructor()
8787
or
8888
// A copy-assignable class may leave both move operations undeclared.
89-
isCopyEnabled(c) and
90-
c.moveAssignable() and
89+
c.copyAssignable() and
9190
not c.declaresMoveConstructor() and
9291
not c.declaresMoveAssignmentOperator()
9392
}

cpp/misra/test/rules/RULE-15-0-1/ImproperlyProvidedSpecialMemberFunctions.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@
3535
| test.cpp:346:7:346:33 | UnmovableBaseNonvirtualDtor | Class 'UnmovableBaseNonvirtualDtor' violates inheritance requirements for special member functions. |
3636
| test.cpp:369:7:369:33 | UnmovablePrivateVirtualDtor | Class 'UnmovablePrivateVirtualDtor' violates inheritance requirements for special member functions. |
3737
| test.cpp:398:7:398:30 | BaseVirtualProtectedDtor | Class 'BaseVirtualProtectedDtor' violates inheritance requirements for special member functions. |
38+
| test.cpp:439:7:439:26 | NonTrivialDestructor | Class 'NonTrivialDestructor' has customized the destructor, but does not customize the copy assignment operator. |
39+
| test.cpp:439:7:439:26 | NonTrivialDestructor | Class 'NonTrivialDestructor' has customized the destructor, but does not customize the copy constructor. |

cpp/misra/test/rules/RULE-15-0-1/ImproperlyProvidedSpecialMemberFunctionsAudit.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
| test.cpp:410:7:410:33 | VirtualProtectedDtorDerived | Class 'VirtualProtectedDtorDerived' is not analyzable because the move assignment operator is not present in the CodeQL database. |
66
| test.cpp:423:8:423:19 | TrivialClass | Class 'TrivialClass' is not analyzable because the destructor and move assignment operator and move constructor are not present in the CodeQL database. |
77
| test.cpp:429:7:429:21 | NonTrivialClass | Class 'NonTrivialClass' is not analyzable because the copy constructor and move assignment operator and move constructor are not present in the CodeQL database. |
8-
| test.cpp:439:7:439:14 | CopyOnly | Class 'CopyOnly' is not analyzable because the destructor is not present in the CodeQL database. |
8+
| test.cpp:450:7:450:14 | CopyOnly | Class 'CopyOnly' is not analyzable because the destructor is not present in the CodeQL database. |

cpp/misra/test/rules/RULE-15-0-1/test.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ class VirtualProtectedDtorDerived : public BaseVirtualProtectedDtor {};
413413

414414
} // namespace fully_specified
415415

416-
namespace audit_results {
416+
namespace implicit_special_members {
417417

418418
struct PodClass { // COMPLIANT - we know PODs are OK.
419419
int x;
@@ -434,6 +434,17 @@ class NonTrivialClass { // NON_COMPLIANT - audit result
434434
~NonTrivialClass() { x = 1; }
435435
};
436436

437+
// CodeQL resolves and stores all of the special member functions in the
438+
// database for this class, so it is not an audit query result.
439+
class NonTrivialDestructor { // NON_COMPLIANT - uncustomized copy ops.
440+
int x;
441+
int y;
442+
443+
public:
444+
COPY_CTOR(NonTrivialDestructor) = default;
445+
~NonTrivialDestructor() { x = 1; }
446+
};
447+
437448
// This class is not a valid category but hard to analyze in the general case.
438449
// This should not be reported as a violation except by the audit query.
439450
class CopyOnly { // NON_COMPLIANT - audit result
@@ -460,4 +471,4 @@ void f(OdrUsedMoveEnabled o) {
460471
o3 = std::move(o);
461472
}
462473

463-
} // namespace audit_results
474+
} // namespace implicit_special_members

0 commit comments

Comments
 (0)