Skip to content

Commit 5283bc8

Browse files
committed
A7-3-1: Report the declaration not the entry
There is no need to report every declaration entry. This commit also fixes performance issues that occurred when making this change.
1 parent 1263d08 commit 5283bc8

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,36 @@ import codingstandards.cpp.autosar
1919
/**
2020
* Holds if the class has a non-virtual member function with the given name.
2121
*/
22+
pragma[noinline, nomagic]
2223
predicate hasNonVirtualMemberFunction(Class clazz, MemberFunction mf, string name) {
2324
mf.getDeclaringType() = clazz and
2425
mf.getName() = name and
2526
not mf.isVirtual()
2627
}
2728

28-
from FunctionDeclarationEntry overridingDecl, MemberFunction hiddenDecl
29+
/**
30+
* Holds if the member function is in a class with the given base class, and has the given name.
31+
*/
32+
pragma[noinline, nomagic]
33+
predicate hasDeclarationBaseClass(MemberFunction mf, Class baseClass, string functionName) {
34+
baseClass = mf.getDeclaringType().getABaseClass() and
35+
functionName = mf.getName()
36+
}
37+
38+
from MemberFunction overridingDecl, MemberFunction hiddenDecl, Class baseClass, string name
2939
where
3040
not isExcluded(overridingDecl, ScopePackage::hiddenInheritedNonOverridableMemberFunctionQuery()) and
3141
// Check if we are overriding a non-virtual inherited member function
32-
hasNonVirtualMemberFunction(overridingDecl.getDeclaration().getDeclaringType().getABaseClass(),
33-
hiddenDecl, overridingDecl.getName()) and
42+
hasNonVirtualMemberFunction(baseClass, hiddenDecl, name) and
43+
hasDeclarationBaseClass(overridingDecl, baseClass, name) and
3444
// Where the hidden member function isn't explicitly brought in scope through a using declaration.
3545
not exists(UsingDeclarationEntry ude |
3646
ude.getDeclaration() = hiddenDecl and
37-
ude.getEnclosingElement() = overridingDecl.getDeclaration().getDeclaringType()
47+
ude.getEnclosingElement() = overridingDecl.getDeclaringType()
3848
) and
3949
// Exclude compiler generated member functions which include things like copy constructor that hide base class
4050
// copy constructors.
41-
not overridingDecl.getDeclaration().isCompilerGenerated()
51+
not overridingDecl.isCompilerGenerated()
4252
select overridingDecl,
43-
"Declaration for member '" + overridingDecl.getName() +
44-
"' hides non-overridable inherited member function $@", hiddenDecl, hiddenDecl.getName()
53+
"Declaration for member '" + name + "' hides non-overridable inherited member function $@",
54+
hiddenDecl, hiddenDecl.getName()
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 | f1 | f1 |
1+
| test.cpp:16:8:16:9 | f1 | Declaration for member 'f1' hides non-overridable inherited member function $@ | test.cpp:7:8:7:9 | f1 | f1 |

0 commit comments

Comments
 (0)