Skip to content

Commit e204fc4

Browse files
authored
Merge pull request #533 from rvermeulen/rvermeulen/fix-400
Address FN reported in #400
2 parents bd425e0 + 02bab28 commit e204fc4

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `M7-3-6` - `UsingDeclarationsUsedInHeaderFiles.ql`:
2+
- Address FN reported in #400. Only using-declarations are exempted from class- and function-scope.

cpp/autosar/src/rules/M7-3-6/UsingDeclarationsUsedInHeaderFiles.ql

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,13 @@ predicate isInClassScope(UsingEntry u) { exists(Class c | u.getEnclosingElement(
2828
from UsingEntry u
2929
where
3030
not isExcluded(u, BannedSyntaxPackage::usingDeclarationsUsedInHeaderFilesQuery()) and
31-
(isInHeaderFile(u) and not isInFunctionScope(u) and not isInClassScope(u))
31+
isInHeaderFile(u) and
32+
(
33+
u instanceof UsingDeclarationEntry
34+
implies
35+
(
36+
not isInFunctionScope(u) and
37+
not isInClassScope(u)
38+
)
39+
)
3240
select u, "Using directive or declaration used in a header file " + u.getFile() + "."
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
| test.h:4:1:4:21 | using namespace std | Using directive or declaration used in a header file test.h. |
2+
| test.h:18:3:18:21 | using namespace std | Using directive or declaration used in a header file test.h. |

cpp/autosar/test/rules/M7-3-6/test.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ namespace my_namespace {
77
int MY_CONST = 0;
88
};
99

10-
int f() {
10+
void f() {
1111

1212
using my_namespace::MY_CONST; // COMPLIANT - function scope
1313

1414
int x = MY_CONST;
1515
}
1616

17+
void test_fn_reported_in_400() {
18+
using namespace std; // NON_COMPLIANT - only using declarations are exempted
19+
// in function scope.
20+
}
1721
#endif

0 commit comments

Comments
 (0)