Skip to content

Commit e489771

Browse files
committed
Fix RULE-6-4-2 performance
1 parent 48a06df commit e489771

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

cpp/common/src/codingstandards/cpp/rules/hiddeninheritedoverridablememberfunction/HiddenInheritedOverridableMemberFunction.qll

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,24 @@ abstract class HiddenInheritedOverridableMemberFunctionSharedQuery extends Query
1212

1313
Query getQuery() { result instanceof HiddenInheritedOverridableMemberFunctionSharedQuery }
1414

15+
class OverridingDeclaration extends FunctionDeclarationEntry {
16+
OverridingDeclaration() { this.getDeclaration().hasDefinition() implies not this.isDefinition() }
17+
}
18+
19+
class HiddenDeclaration extends OverridingDeclaration {
20+
HiddenDeclaration() {
21+
// Check if we are overriding a virtual inherited member function
22+
this.getDeclaration().isVirtual() and
23+
// Exclude private member functions, which cannot be inherited.
24+
not this.getDeclaration().(MemberFunction).isPrivate()
25+
}
26+
}
27+
1528
query predicate problems(
16-
FunctionDeclarationEntry overridingDecl, string message, FunctionDeclarationEntry hiddenDecl,
29+
OverridingDeclaration overridingDecl, string message, HiddenDeclaration hiddenDecl,
1730
string hiddenDecl_string
1831
) {
1932
not isExcluded(overridingDecl, getQuery()) and
20-
// Check if we are overriding a virtual inherited member function
21-
hiddenDecl.getDeclaration().isVirtual() and
22-
// Exclude private member functions, which cannot be inherited.
23-
not hiddenDecl.getDeclaration().(MemberFunction).isPrivate() and
2433
// The overriding declaration hides the hidden declaration if:
2534
(
2635
// 1. the overriding declaration overrides a function in a base class that is an overload of the hidden declaration
@@ -46,9 +55,6 @@ query predicate problems(
4655
overridingDecl.getDeclaration().getDeclaringType().getABaseClass() =
4756
hiddenDecl.getDeclaration().getDeclaringType()
4857
) and
49-
// Limit the results to the declarations and not the definitions, if any.
50-
(overridingDecl.getDeclaration().hasDefinition() implies not overridingDecl.isDefinition()) and
51-
(hiddenDecl.getDeclaration().hasDefinition() implies not hiddenDecl.isDefinition()) and
5258
message =
5359
"Declaration for member '" + overridingDecl.getName() +
5460
"' hides overridable inherited member function $@" and

0 commit comments

Comments
 (0)