Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions change_notes/2024-07-16-fix-fp-606-A2-7-3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `A2-7-3` - `UndocumentedUserDefinedType.ql`:
- Fixes #606. Fix false positive relating to friend functions in template classes.
6 changes: 5 additions & 1 deletion cpp/autosar/src/rules/A2-7-3/UndocumentedUserDefinedType.ql
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ class DocumentableDeclaration extends Declaration {
// Exclude instantiated template functions, which cannot reasonably be documented.
not this.(Function).isFromTemplateInstantiation(_) and
// Exclude anonymous lambda functions.
not exists(LambdaExpression lc | lc.getLambdaFunction() = this)
not exists(LambdaExpression lc | lc.getLambdaFunction() = this) and
//Exclude friend functions (because they have 2 entries in the database), and only one shows documented truly
not exists(FriendDecl d |
d.getFriend().(Function).getDefinition() = this.getADeclarationEntry()
)
or
this instanceof MemberVariable and
declarationType = "member variable" and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
| test.cpp:101:6:101:6 | definition of e | Declaration entry for function e is missing documentation. |
| test.cpp:108:1:108:30 | definition of message_to_string_undocumented | Declaration entry for function message_to_string_undocumented is missing documentation. |
| test.cpp:180:21:180:24 | definition of kBar | Declaration entry for member variable kBar is missing documentation. |
| test.cpp:227:14:227:17 | definition of foo3 | Declaration entry for function foo3 is missing documentation. |
32 changes: 31 additions & 1 deletion cpp/autosar/test/rules/A2-7-3/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,34 @@ void testFunctionScope() {
void fNestedTest(); // COMPLIANT - in function scope
};
};
}
}

/// Test documentation
template <typename T> class ClassG { // COMPLIANT
private:
/// Test documentation
int x; // COMPLIANT

public:
/// Test documentation
friend int foo(ClassG<T> g) { return g.x; } // COMPLIANT
};

/// Test documentation
void test() { // COMPLIANT
ClassG<int> g;
foo(g);
}

/// Test documentation
class ClassG2 { // COMPLIANT
public:
/// Test documentation
friend int foo2() { return 1; } // COMPLIANT
};

/// Test documentation
class ClassG3 { // COMPLIANT
public:
friend int foo3() { return 1; } // NON_COMPLIANT
};
Loading