Skip to content

Commit 46e5eba

Browse files
committed
A7-3-1: Refactor to avoid join on name
Refactor to: 1. Avoid any potential performance problems from equating names of two member functions. 2. Report the Declaration, not the DeclarationEntry of the hidden function, which reduces duplication.
1 parent 47c8a57 commit 46e5eba

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

cpp/autosar/src/rules/A7-3-1/HiddenInheritedNonOverridableMemberFunction.ql

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,24 @@
1616
import cpp
1717
import codingstandards.cpp.autosar
1818

19-
from FunctionDeclarationEntry overridingDecl, FunctionDeclarationEntry hiddenDecl
19+
/**
20+
* Holds if the class has a non-virtual member function with the given name.
21+
*/
22+
predicate hasNonVirtualMemberFunction(Class clazz, MemberFunction mf, string name) {
23+
mf.getDeclaringType() = clazz and
24+
mf.getName() = name and
25+
not mf.isVirtual()
26+
}
27+
28+
from FunctionDeclarationEntry overridingDecl, MemberFunction hiddenDecl
2029
where
2130
not isExcluded(overridingDecl, ScopePackage::hiddenInheritedNonOverridableMemberFunctionQuery()) and
2231
// Check if we are overriding a non-virtual inherited member function
23-
overridingDecl.getName() = hiddenDecl.getName() and
24-
overridingDecl.getDeclaration().getDeclaringType().getABaseClass() =
25-
hiddenDecl.getDeclaration().getDeclaringType() and
26-
not hiddenDecl.getDeclaration().isVirtual() and
32+
hasNonVirtualMemberFunction(overridingDecl.getDeclaration().getDeclaringType().getABaseClass(),
33+
hiddenDecl, overridingDecl.getName()) and
2734
// Where the hidden member function isn't explicitly brought in scope through a using declaration.
2835
not exists(UsingDeclarationEntry ude |
29-
ude.getDeclaration() = hiddenDecl.getDeclaration() and
36+
ude.getDeclaration() = hiddenDecl and
3037
ude.getEnclosingElement() = overridingDecl.getDeclaration().getDeclaringType() and
3138
ude.getLocation().getStartLine() < overridingDecl.getLocation().getStartLine()
3239
) and
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| test.cpp:16:8:16:9 | declaration of f1 | Declaration for member 'f1' hides non-overridable inherited member function $@ | test.cpp:7:8:7:9 | declaration of f1 | f1 |
1+
| test.cpp:16:8:16:9 | declaration of f1 | Declaration for member 'f1' hides non-overridable inherited member function $@ | test.cpp:7:8:7:9 | f1 | f1 |

0 commit comments

Comments
 (0)