Skip to content

Commit 569fa76

Browse files
committed
RULE-8-7: Support use in headers.
1 parent d6710e0 commit 569fa76

File tree

4 files changed

+7
-2
lines changed

4 files changed

+7
-2
lines changed

c/misra/src/rules/RULE-8-7/ShouldNotBeDefinedWithExternalLinkage.ql

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ predicate isReferencedInTranslationUnit(
4040
ExternalIdentifiers e, ExternalIdentifierReference r, TranslationUnit t
4141
) {
4242
r.getExternalIdentifierTarget() = e and
43-
r.getFile() = t
43+
// Used within the translation unit or an included header
44+
r.getFile() = t.getAUserFile()
4445
}
4546

4647
from ExternalIdentifiers e, ExternalIdentifierReference a1, TranslationUnit t1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
| test2.h:2:13:2:14 | f6 | Declaration with external linkage is accessed in only one translation unit $@. | test2.h:3:22:3:23 | call to f6 | call to f6 |
12
| test.c:3:5:3:6 | i1 | Declaration with external linkage is accessed in only one translation unit $@. | test.c:11:3:11:4 | i1 | i1 |
23
| test.c:4:5:4:6 | i2 | Declaration with external linkage is accessed in only one translation unit $@. | test.c:12:3:12:4 | i2 | i2 |
34
| test.c:6:6:6:7 | f2 | Declaration with external linkage is accessed in only one translation unit $@. | test.c:14:3:14:4 | call to f2 | call to f2 |

c/misra/test/rules/RULE-8-7/test1.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "test.h"
1+
#include "test2.h"
22
void f() {
33
i = 0;
44
f1();

c/misra/test/rules/RULE-8-7/test2.h

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "test.h"
2+
extern void f6() {} // NON_COMPLIANT
3+
static void test() { f6(); }

0 commit comments

Comments
 (0)