Skip to content

Commit

Permalink
Merge pull request #533 from rvermeulen/rvermeulen/fix-400
Browse files Browse the repository at this point in the history
Address FN reported in #400
  • Loading branch information
knewbury01 authored Feb 14, 2024
2 parents bd425e0 + 02bab28 commit e204fc4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions change_notes/2024-02-13-fix-fn-M7-3-6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `M7-3-6` - `UsingDeclarationsUsedInHeaderFiles.ql`:
- Address FN reported in #400. Only using-declarations are exempted from class- and function-scope.
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,13 @@ predicate isInClassScope(UsingEntry u) { exists(Class c | u.getEnclosingElement(
from UsingEntry u
where
not isExcluded(u, BannedSyntaxPackage::usingDeclarationsUsedInHeaderFilesQuery()) and
(isInHeaderFile(u) and not isInFunctionScope(u) and not isInClassScope(u))
isInHeaderFile(u) and
(
u instanceof UsingDeclarationEntry
implies
(
not isInFunctionScope(u) and
not isInClassScope(u)
)
)
select u, "Using directive or declaration used in a header file " + u.getFile() + "."
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
| test.h:4:1:4:21 | using namespace std | Using directive or declaration used in a header file test.h. |
| test.h:18:3:18:21 | using namespace std | Using directive or declaration used in a header file test.h. |
6 changes: 5 additions & 1 deletion cpp/autosar/test/rules/M7-3-6/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ namespace my_namespace {
int MY_CONST = 0;
};

int f() {
void f() {

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

int x = MY_CONST;
}

void test_fn_reported_in_400() {
using namespace std; // NON_COMPLIANT - only using declarations are exempted
// in function scope.
}
#endif

0 comments on commit e204fc4

Please sign in to comment.