Skip to content

Commit e90cd3f

Browse files
committed
A2-7-3: fix #606, omit fp in friend function declarations in template classes
1 parent d17443b commit e90cd3f

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
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

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @name A2-7-3: Declarations of 'user-defined' types, member variables and functions should be documented
44
* @description All declarations of 'user-defined' types, static and non-static data members,
55
* functions and methods shall be preceded by documentation.
6-
* @kind problem
6+
* @ kind problem
77
* @precision very-high
88
* @problem.severity recommendation
99
* @tags external/autosar/id/a2-7-3
@@ -44,7 +44,11 @@ class DocumentableDeclaration extends Declaration {
4444
// Exclude instantiated template functions, which cannot reasonably be documented.
4545
not this.(Function).isFromTemplateInstantiation(_) and
4646
// Exclude anonymous lambda functions.
47-
not exists(LambdaExpression lc | lc.getLambdaFunction() = this)
47+
not exists(LambdaExpression lc | lc.getLambdaFunction() = this) and
48+
//Exclude friend functions (because they have 2 entries in the database), and only one shows documented truly
49+
not exists(FriendDecl d |
50+
d.getFriend().(Function).getDefinition() = this.getADeclarationEntry()
51+
)
4852
or
4953
this instanceof MemberVariable and
5054
declarationType = "member variable" and

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

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
| test.cpp:81:6:81:6 | definition of e | Declaration entry for function e is missing documentation. |
88
| test.cpp:88:1:88:30 | definition of message_to_string_undocumented | Declaration entry for function message_to_string_undocumented is missing documentation. |
99
| test.cpp:160:21:160:24 | definition of kBar | Declaration entry for member variable kBar is missing documentation. |
10+
| test.cpp:207:14:207: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
@@ -175,4 +175,34 @@ void testFunctionScope() {
175175
void fNestedTest(); // COMPLIANT - in function scope
176176
};
177177
};
178-
}
178+
}
179+
180+
/// Test documentation
181+
template <typename T> class ClassG { // COMPLIANT
182+
private:
183+
/// Test documentation
184+
int x; // COMPLIANT
185+
186+
public:
187+
/// Test documentation
188+
friend int foo(ClassG<T> g) { return g.x; } // COMPLIANT
189+
};
190+
191+
/// Test documentation
192+
void test() { // COMPLIANT
193+
ClassG<int> g;
194+
foo(g);
195+
}
196+
197+
/// Test documentation
198+
class ClassG2 { // COMPLIANT
199+
public:
200+
/// Test documentation
201+
friend int foo2() { return 1; } // COMPLIANT
202+
};
203+
204+
/// Test documentation
205+
class ClassG3 { // COMPLIANT
206+
public:
207+
friend int foo3() { return 1; } // NON_COMPLIANT
208+
};

0 commit comments

Comments
 (0)