Skip to content

Commit 6a68398

Browse files
authored
Merge pull request #1208 from castler/fix-rule-13-3-1-implicit-dtor
Fix RULE-13-3-1 false positives for implicit destructors
2 parents c401e20 + 476df37 commit 6a68398

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- `RULE-13-3-1` - `MemberSpecifiersNotUsedAppropriately.ql`:
2+
- Fixed false positives on implicitly declared member functions, most
3+
commonly the implicit destructor of a class deriving from a class with a
4+
virtual destructor. The rule applies to user-declared member functions
5+
only, and an implicit destructor cannot carry `override` or `final`.

‎cpp/misra/src/rules/RULE-13-3-1/MemberSpecifiersNotUsedAppropriately.ql‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import codingstandards.cpp.misra
2020
from MemberFunction f, string message
2121
where
2222
not isExcluded(f, Classes2Package::memberSpecifiersNotUsedAppropriatelyQuery()) and
23+
// Only user-declared member functions are in scope, not implicitly declared
24+
// ones such as an implicit destructor.
25+
not f.isCompilerGenerated() and
2326
(
2427
// Case 1: Specifiers incompatible with explicitly virtual
2528
f.isDeclaredVirtual() and

‎cpp/misra/test/rules/RULE-13-3-1/test.cpp‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,13 @@ class C15 : public NonvirtualDestructorBase {
104104
public:
105105
virtual ~C15() =
106106
default; // COMPLIANT: Note that this does not violate rule 6.4.2
107-
};
107+
};
108+
109+
class C16 : public VirtualDestructorBase {
110+
// COMPLIANT: the destructor is implicitly declared, not user-declared
111+
};
112+
113+
class C17 : public VirtualDestructorBase {
114+
public:
115+
C17() = default; // COMPLIANT: implicit virtual destructor not user-declared
116+
};

0 commit comments

Comments
 (0)