Skip to content

Commit c3977f2

Browse files
committed
Migrate M17-0-2 to StandardLibraryNames.
1 parent 7c94c8c commit c3977f2

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

cpp/autosar/src/rules/M17-0-2/NameOfStandardLibraryMacroOrObjectReused.ql

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616

1717
import cpp
1818
import codingstandards.cpp.autosar
19-
import codingstandards.cpp.Naming
19+
import codingstandards.cpp.StandardLibraryNames
2020

21-
from Locatable l, string s, string t
21+
module TargetedCLibrary = CStandardLibrary::C99;
22+
23+
module TargetedCppLibrary = CppStandardLibrary::Cpp14;
24+
25+
from Locatable l, string s, string t, string header, string standard
2226
where
2327
not isExcluded(l, NamingPackage::nameOfStandardLibraryMacroOrObjectReusedQuery()) and
2428
l.fromSource() and
@@ -28,8 +32,21 @@ where
2832
s = l.(GlobalOrNamespaceVariable).getName() and t = "Object"
2933
) and
3034
(
31-
Naming::Cpp14::hasStandardLibraryMacroName(s)
35+
standard = TargetedCppLibrary::getName() and
36+
(
37+
TargetedCppLibrary::hasMacroName(header, s, _)
38+
or
39+
TargetedCppLibrary::hasObjectName(header, _, s, _, _)
40+
)
3241
or
33-
Naming::Cpp14::hasStandardLibraryObjectName(s)
42+
standard = TargetedCLibrary::getName() and
43+
(
44+
header = max(string candidateHeader | TargetedCLibrary::hasMacroName(candidateHeader, s, _))
45+
or
46+
header =
47+
max(string candidateHeader | TargetedCLibrary::hasObjectName(candidateHeader, _, s, _, _))
48+
)
3449
)
35-
select l, t + " reuses the name " + s + " from the standard library."
50+
select l,
51+
t + " reuses the name " + s + " from the " + standard + " standard library header <" + header +
52+
">."
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| test.cpp:1:1:1:14 | #define NULL 0 | Macro reuses the name NULL from the standard library. |
2-
| test.cpp:3:5:3:10 | tzname | Object reuses the name tzname from the standard library. |
1+
| test.cpp:1:1:1:14 | #define NULL 0 | Macro reuses the name NULL from the C99 standard library header <wchar.h>. |
2+
| test.cpp:3:5:3:8 | cout | Object reuses the name cout from the C++14 standard library header <iostream>. |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#define NULL 0 // NON_COMPLIANT
22

3-
int tzname = 0; // NON_COMPLIANT
3+
int cout = 0; // NON_COMPLIANT

0 commit comments

Comments
 (0)