Skip to content

Commit 73736d9

Browse files
committed
A7-3-1: Exclude private member functions
Private member functions can't be inherited.
1 parent 6e35de7 commit 73736d9

6 files changed

+23
-8
lines changed

change_notes/2023-09-28-a7-3-1-updates.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
- Reduce duplication when reporting the hidden function by reporting only one declaration entry.
44
- Improve performance by eliminating a number of bad join orders.
55
- Fix false positives where the using declaration occurred after the function declaration.
6-
- Exclude special member functions, which cannot be inherited.
6+
- Exclude special member functions, which cannot be inherited.
7+
- Exclude private member functions, which cannot be inherited.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ pragma[noinline, nomagic]
2424
predicate hasNonVirtualMemberFunction(Class clazz, MemberFunction mf, string name) {
2525
mf.getDeclaringType() = clazz and
2626
mf.getName() = name and
27-
not mf.isVirtual()
27+
not mf.isVirtual() and
28+
// Exclude private member functions, which cannot be inherited.
29+
not mf.isPrivate()
2830
}
2931

3032
/**

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ where
2121
not isExcluded(overridingDecl, ScopePackage::hiddenInheritedOverridableMemberFunctionQuery()) and
2222
// Check if we are overriding a virtual inherited member function
2323
hiddenDecl.getDeclaration().isVirtual() and
24+
// Exclude private member functions, which cannot be inherited.
25+
not hiddenDecl.getDeclaration().(MemberFunction).isPrivate() and
2426
// The overriding declaration hides the hidden declaration if:
2527
(
2628
// 1. the overriding declaration overrides a function in a base class that is an overload of the hidden declaration
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
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 |
1+
| test.cpp:20:8:20:9 | f1 | Declaration for member 'f1' hides non-overridable inherited member function $@ | test.cpp:7:8:7:9 | f1 | f1 |
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
| test.cpp:18:8:18:9 | declaration of f2 | Declaration for member 'f2' hides overridable inherited member function $@ | test.cpp:9:16:9:17 | declaration of f2 | f2 |
2-
| test.cpp:18:8:18:9 | declaration of f2 | Declaration for member 'f2' hides overridable inherited member function $@ | test.cpp:11:16:11:17 | declaration of f2 | f2 |
3-
| test.cpp:23:8:23:9 | declaration of f2 | Declaration for member 'f2' hides overridable inherited member function $@ | test.cpp:9:16:9:17 | declaration of f2 | f2 |
4-
| test.cpp:23:8:23:9 | declaration of f2 | Declaration for member 'f2' hides overridable inherited member function $@ | test.cpp:10:16:10:17 | declaration of f2 | f2 |
5-
| test.cpp:23:8:23:9 | declaration of f2 | Declaration for member 'f2' hides overridable inherited member function $@ | test.cpp:11:16:11:17 | declaration of f2 | f2 |
1+
| test.cpp:22:8:22:9 | declaration of f2 | Declaration for member 'f2' hides overridable inherited member function $@ | test.cpp:9:16:9:17 | declaration of f2 | f2 |
2+
| test.cpp:22:8:22:9 | declaration of f2 | Declaration for member 'f2' hides overridable inherited member function $@ | test.cpp:11:16:11:17 | declaration of f2 | f2 |
3+
| test.cpp:27:8:27:9 | declaration of f2 | Declaration for member 'f2' hides overridable inherited member function $@ | test.cpp:9:16:9:17 | declaration of f2 | f2 |
4+
| test.cpp:27:8:27:9 | declaration of f2 | Declaration for member 'f2' hides overridable inherited member function $@ | test.cpp:10:16:10:17 | declaration of f2 | f2 |
5+
| test.cpp:27:8:27:9 | declaration of f2 | Declaration for member 'f2' hides overridable inherited member function $@ | test.cpp:11:16:11:17 | declaration of f2 | f2 |

cpp/autosar/test/rules/A7-3-1/test.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ class C1 {
99
virtual void f2(int);
1010
virtual void f2(double);
1111
virtual void f2(S1);
12+
13+
private:
14+
void f3(int);
15+
void f4(int);
1216
};
1317

1418
class C2 : public C1 {
@@ -81,4 +85,10 @@ void f2() {
8185
class C6 : public C1 {
8286
public:
8387
C6 &operator=(const C6 &); // COMPLIANT
88+
};
89+
90+
class C7 : public C1 {
91+
void f3(int); // COMPLIANT
92+
93+
void f4(int); // COMPLIANT
8494
};

0 commit comments

Comments
 (0)