forked from github/codeql-coding-standards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDestructorOfABaseClassNotPublicVirtual.ql
More file actions
37 lines (32 loc) · 1.75 KB
/
DestructorOfABaseClassNotPublicVirtual.ql
File metadata and controls
37 lines (32 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* @id cpp/autosar/destructor-of-a-base-class-not-public-virtual
* @name A12-4-1: Destructor of a base class shall be public virtual, public override or protected non-virtual
* @description Destructor of a base class shall be public virtual or public override to ensure that
* destructors for derived types are invoked when the derived types are destroyed
* through a pointer or reference to its base class. If destruction through a base
* class pointer or reference is prohibited, the destructor of the base class should be
* protected.
* @kind problem
* @precision very-high
* @problem.severity warning
* @tags external/autosar/id/a12-4-1
* correctness
* external/autosar/allocated-target/implementation
* external/autosar/enforcement/automated
* external/autosar/obligation/required
*/
import cpp
import codingstandards.cpp.autosar
import codingstandards.cpp.Class
predicate isPublicOverride(Destructor d) { d.isPublic() and d.hasSpecifier("override") }
predicate isPublicVirtual(Destructor d) { d.isPublic() and d.isVirtual() }
predicate isProtectedNonVirtual(Destructor d) { d.isProtected() and not d.isVirtual() }
from Destructor d
where
not isExcluded(d, VirtualFunctionsPackage::destructorOfABaseClassNotPublicVirtualQuery()) and
d.getDeclaringType() instanceof BaseClass and
(not isPublicOverride(d) and not isProtectedNonVirtual(d) and not isPublicVirtual(d))
// Report the declaration entry in the class body, as that is where the access specifier should be set
select getDeclarationEntryInClassDeclaration(d),
"Destructor of base class '" + d.getDeclaringType().getQualifiedName() +
"' is not declared as public virtual, public override, or protected non-virtual."