Skip to content

Commit c530b59

Browse files
committed
A2-7-3: Exclude function scope declarations
1 parent a530e5a commit c530b59

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* `A2-7-3` - reduce false positives by:
2+
- Excluding declarations in function scope. The rationale is that these declarations are not exposed outside the scope of the function.
3+

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
import cpp
1818
import codingstandards.cpp.autosar
1919

20+
private predicate isInFunctionScope(Declaration d) {
21+
// Type declared in function
22+
exists(d.(UserType).getEnclosingFunction())
23+
or
24+
// Member declared in type which is in function scope
25+
isInFunctionScope(d.getDeclaringType())
26+
}
27+
2028
/**
2129
* A declaration which is required to be preceded by documentation by AUTOSAR A2-7-3.
2230
*/
@@ -96,6 +104,7 @@ from DocumentableDeclaration d, DeclarationEntry de
96104
where
97105
not isExcluded(de, CommentsPackage::undocumentedUserDefinedTypeQuery()) and
98106
not isExcluded(d, CommentsPackage::undocumentedUserDefinedTypeQuery()) and
107+
not isInFunctionScope(d) and
99108
d.getAnUndocumentedDeclarationEntry() = de
100109
select de,
101110
"Declaration entry for " + d.getDeclarationType() + " " + d.getName() +

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,19 @@ template <typename T> class A2_7_3 final {
160160
const std::string kBar{"bar"}; // NON_COMPLIANT
161161
};
162162
/// @brief This is the instantiateA2_7_3 documentation
163-
void instantiateA2_7_3() { A2_7_3<int> instance; }
163+
void instantiateA2_7_3() { A2_7_3<int> instance; }
164+
165+
/// Test documentation
166+
void testFunctionScope() {
167+
using my_float = float;
168+
class ClassF { // COMPLIANT - in function scope
169+
public:
170+
int m_x; // COMPLIANT - in function scope
171+
void fTest(); // COMPLIANT - in function scope
172+
class ClassFNested {
173+
public:
174+
int m_nested_x; // COMPLIANT - in function scope
175+
void fNestedTest(); // COMPLIANT - in function scope
176+
};
177+
};
178+
}

0 commit comments

Comments
 (0)