Skip to content

A2-7-3: exclude false declaration entries for friend functions in template classes #644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
21 changes: 10 additions & 11 deletions cpp/autosar/test/rules/A2-7-3/UndocumentedUserDefinedType.expected
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
| test.cpp:74:8:74:8 | declaration of j | Declaration entry for function j is missing documentation. |
| test.cpp:75:8:75:8 | declaration of k | Declaration entry for function k is missing documentation. |
| test.cpp:90:7:90:12 | definition of ClassD | Declaration entry for user-defined type ClassD is missing documentation. |
| test.cpp:92:7:92:7 | definition of a | Declaration entry for member variable a is missing documentation. |
| test.cpp:93:14:93:14 | declaration of b | Declaration entry for member variable b is missing documentation. |
| test.cpp:94:8:94:8 | declaration of f | Declaration entry for function f is missing documentation. |
| test.cpp:96:7:96:7 | definition of c | Declaration entry for member variable c is missing documentation. |
| test.cpp:98:6:98:6 | declaration of d | Declaration entry for function d is missing documentation. |
| 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:70:7:70:12 | definition of ClassD | Declaration entry for user-defined type ClassD is missing documentation. |
| test.cpp:72:7:72:7 | definition of a | Declaration entry for member variable a is missing documentation. |
| test.cpp:73:14:73:14 | declaration of b | Declaration entry for member variable b is missing documentation. |
| test.cpp:74:8:74:8 | declaration of f | Declaration entry for function f is missing documentation. |
| test.cpp:76:7:76:7 | definition of c | Declaration entry for member variable c is missing documentation. |
| test.cpp:78:6:78:6 | declaration of d | Declaration entry for function d is missing documentation. |
| test.cpp:81:6:81:6 | definition of e | Declaration entry for function e is missing documentation. |
| test.cpp:88:1:88:30 | definition of message_to_string_undocumented | Declaration entry for function message_to_string_undocumented is missing documentation. |
| test.cpp:160:21:160:24 | definition of kBar | Declaration entry for member variable kBar is missing documentation. |
| test.cpp:207:14:207: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