Skip to content

Commit 1263d08

Browse files
committed
A7-3-1: Ignore order of using and decl
The filter on order between overriding declaration and using was problematic because: 1. It produced a bad join order related to start lines. 2. It did not check if they were in the same file. 3. It used the wrong declaration - the order of the overriding declaration and the using declaration doesn't matter. I think the intention was to confirm that the hidden declaration appeared before the using declaration (so that it was in scope), but errors of this kind would be identified by the DefinitionNotConsideredForUnqualifiedLookup.ql query, so there's no need to factor that in here.
1 parent 46e5eba commit 1263d08

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ where
3434
// Where the hidden member function isn't explicitly brought in scope through a using declaration.
3535
not exists(UsingDeclarationEntry ude |
3636
ude.getDeclaration() = hiddenDecl and
37-
ude.getEnclosingElement() = overridingDecl.getDeclaration().getDeclaringType() and
38-
ude.getLocation().getStartLine() < overridingDecl.getLocation().getStartLine()
37+
ude.getEnclosingElement() = overridingDecl.getDeclaration().getDeclaringType()
3938
) and
4039
// Exclude compiler generated member functions which include things like copy constructor that hide base class
4140
// copy constructors.

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void f1() {
4747
l1.f1(0); // calls C2::f1(double) instead of C1::f1(int)
4848
l1.f2(0); // calls C2::f2(double) instead of C1::f2(int)
4949
// S1 s1;
50-
// l1.f2(s1); Won't compile because there is no suitable conversion fro S1 to
50+
// l1.f2(s1); Won't compile because there is no suitable conversion from S1 to
5151
// double.
5252
C1 &l2{l1};
5353
l2.f1(0); // calls C1::f1(int)
@@ -60,3 +60,20 @@ void f1() {
6060
S1 l4;
6161
l3.f2(l4); // calls C1:f2(S1)
6262
}
63+
64+
class C5 : public C1 {
65+
public:
66+
void f1(double); // COMPLIANT
67+
using C1::f1; // order of using and f1 declaration is not relevant
68+
69+
void f2(double) override; // COMPLIANT
70+
using C1::f2; // order of using and f1 declaration is not relevant
71+
};
72+
73+
void f2() {
74+
C5 c5;
75+
c5.f1(0); // calls C1::f1(int)
76+
c5.f1(0.0); // calls C5::f1(double)
77+
c5.f2(0); // calls C1::f2(int)
78+
c5.f2(0.0); // calls C5::f2(double)
79+
}

0 commit comments

Comments
 (0)