Skip to content

Commit a989829

Browse files
authored
Merge pull request #644 from knewbury01/knewbury01/fix-606
A2-7-3: exclude false declaration entries for friend functions in template classes
2 parents 29ade52 + 5367a8d commit a989829

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A2-7-3` - `UndocumentedUserDefinedType.ql`:
2+
- Fixes #606. Fix false positive relating to friend functions in template classes.

cpp/autosar/src/rules/A2-7-3/UndocumentedUserDefinedType.ql

+5-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ class DocumentableDeclaration extends Declaration {
7777
// Exclude instantiated template functions, which cannot reasonably be documented.
7878
not this.(Function).isFromTemplateInstantiation(_) and
7979
// Exclude anonymous lambda functions.
80-
not exists(LambdaExpression lc | lc.getLambdaFunction() = this)
80+
not exists(LambdaExpression lc | lc.getLambdaFunction() = this) and
81+
//Exclude friend functions (because they have 2 entries in the database), and only one shows documented truly
82+
not exists(FriendDecl d |
83+
d.getFriend().(Function).getDefinition() = this.getADeclarationEntry()
84+
)
8185
or
8286
this instanceof MemberVariable and
8387
declarationType = "member variable" and

cpp/autosar/test/rules/A2-7-3/UndocumentedUserDefinedType.expected

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
| test.cpp:101:6:101:6 | definition of e | Declaration entry for function e is missing documentation. |
1010
| test.cpp:108:1:108:30 | definition of message_to_string_undocumented | Declaration entry for function message_to_string_undocumented is missing documentation. |
1111
| test.cpp:180:21:180:24 | definition of kBar | Declaration entry for member variable kBar is missing documentation. |
12+
| test.cpp:227:14:227:17 | definition of foo3 | Declaration entry for function foo3 is missing documentation. |

cpp/autosar/test/rules/A2-7-3/test.cpp

+31-1
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,34 @@ void testFunctionScope() {
195195
void fNestedTest(); // COMPLIANT - in function scope
196196
};
197197
};
198-
}
198+
}
199+
200+
/// Test documentation
201+
template <typename T> class ClassG { // COMPLIANT
202+
private:
203+
/// Test documentation
204+
int x; // COMPLIANT
205+
206+
public:
207+
/// Test documentation
208+
friend int foo(ClassG<T> g) { return g.x; } // COMPLIANT
209+
};
210+
211+
/// Test documentation
212+
void test() { // COMPLIANT
213+
ClassG<int> g;
214+
foo(g);
215+
}
216+
217+
/// Test documentation
218+
class ClassG2 { // COMPLIANT
219+
public:
220+
/// Test documentation
221+
friend int foo2() { return 1; } // COMPLIANT
222+
};
223+
224+
/// Test documentation
225+
class ClassG3 { // COMPLIANT
226+
public:
227+
friend int foo3() { return 1; } // NON_COMPLIANT
228+
};

0 commit comments

Comments
 (0)