Skip to content

Commit 740c76d

Browse files
committed
Migrate A17-0-1 to use ReservedName
1 parent cb5ddf5 commit 740c76d

File tree

3 files changed

+36
-56
lines changed

3 files changed

+36
-56
lines changed

cpp/autosar/src/rules/A17-0-1/ReservedIdentifiersMacrosAndFunctionsAreDefinedRedefinedOrUndefined.ql

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,11 @@
2222

2323
import cpp
2424
import codingstandards.cpp.autosar
25-
import codingstandards.cpp.Naming
25+
import codingstandards.cpp.ReservedNames
2626

27-
predicate isLocatedInNamespaceBody(NamespaceDeclarationEntry n, PreprocessorDirective m) {
28-
m.getFile() = n.getFile() and
29-
m.getLocation().getStartLine() >= n.getBodyLocation().getStartLine() and
30-
m.getLocation().getEndLine() <= n.getBodyLocation().getEndLine()
31-
}
32-
33-
from PreprocessorDirective ppd, string name
27+
from PreprocessorDirective ppd, string reason
3428
where
3529
not isExcluded(ppd,
3630
BannedLibrariesPackage::reservedIdentifiersMacrosAndFunctionsAreDefinedRedefinedOrUndefinedQuery()) and
37-
(
38-
ppd.(Macro).hasName(name)
39-
or
40-
ppd.(PreprocessorUndef).getName() = name
41-
) and
42-
(
43-
Naming::Cpp14::hasStandardLibraryMacroName(name)
44-
or
45-
Naming::Cpp14::hasStandardLibraryObjectName(name)
46-
or
47-
// Reserved everywhere according to [global.names]
48-
name.regexpMatch("(__|_[A-Z]).*")
49-
or
50-
// Reserved only in the global namespace according to [global.names]
51-
name.regexpMatch("_.*") and
52-
not isLocatedInNamespaceBody(_, ppd)
53-
)
54-
select ppd, "Reserved identifier '" + name + "' has been undefined or redefined."
31+
ReservedNames::Cpp14::isMacroUsingReservedIdentifier(ppd, reason)
32+
select ppd, reason
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
| test.cpp:1:1:1:12 | #undef errno | Reserved identifier 'errno' has been undefined or redefined. |
2-
| test.cpp:2:1:2:15 | #define errno 0 | Reserved identifier 'errno' has been undefined or redefined. |
3-
| test.cpp:4:1:4:13 | #undef assert | Reserved identifier 'assert' has been undefined or redefined. |
4-
| test.cpp:5:1:5:27 | #define assert(condition) 0 | Reserved identifier 'assert' has been undefined or redefined. |
5-
| test.cpp:7:1:7:15 | #undef __LINE__ | Reserved identifier '__LINE__' has been undefined or redefined. |
6-
| test.cpp:8:1:8:18 | #define __LINE__ 0 | Reserved identifier '__LINE__' has been undefined or redefined. |
7-
| test.cpp:10:1:10:15 | #undef __FILE__ | Reserved identifier '__FILE__' has been undefined or redefined. |
8-
| test.cpp:11:1:11:18 | #define __FILE__ 0 | Reserved identifier '__FILE__' has been undefined or redefined. |
9-
| test.cpp:13:1:13:15 | #undef __DATE__ | Reserved identifier '__DATE__' has been undefined or redefined. |
10-
| test.cpp:14:1:14:18 | #define __DATE__ 0 | Reserved identifier '__DATE__' has been undefined or redefined. |
11-
| test.cpp:16:1:16:15 | #undef __TIME__ | Reserved identifier '__TIME__' has been undefined or redefined. |
12-
| test.cpp:17:1:17:18 | #define __TIME__ 0 | Reserved identifier '__TIME__' has been undefined or redefined. |
13-
| test.cpp:19:1:19:15 | #undef __STDC__ | Reserved identifier '__STDC__' has been undefined or redefined. |
14-
| test.cpp:20:1:20:18 | #define __STDC__ 0 | Reserved identifier '__STDC__' has been undefined or redefined. |
15-
| test.cpp:22:1:22:22 | #undef __STDC_HOSTED__ | Reserved identifier '__STDC_HOSTED__' has been undefined or redefined. |
16-
| test.cpp:23:1:23:25 | #define __STDC_HOSTED__ 0 | Reserved identifier '__STDC_HOSTED__' has been undefined or redefined. |
17-
| test.cpp:25:1:25:18 | #undef __cplusplus | Reserved identifier '__cplusplus' has been undefined or redefined. |
18-
| test.cpp:26:1:26:21 | #define __cplusplus 0 | Reserved identifier '__cplusplus' has been undefined or redefined. |
19-
| test.cpp:28:1:28:25 | #undef __STDCPP_THREADS__ | Reserved identifier '__STDCPP_THREADS__' has been undefined or redefined. |
20-
| test.cpp:29:1:29:28 | #define __STDCPP_THREADS__ 0 | Reserved identifier '__STDCPP_THREADS__' has been undefined or redefined. |
21-
| test.cpp:31:1:31:19 | #undef __FUNCTION__ | Reserved identifier '__FUNCTION__' has been undefined or redefined. |
22-
| test.cpp:32:1:32:22 | #define __FUNCTION__ 0 | Reserved identifier '__FUNCTION__' has been undefined or redefined. |
23-
| test.cpp:34:1:34:11 | #undef _Foo | Reserved identifier '_Foo' has been undefined or redefined. |
24-
| test.cpp:35:1:35:12 | #define _Foo | Reserved identifier '_Foo' has been undefined or redefined. |
25-
| test.cpp:37:1:37:11 | #undef _foo | Reserved identifier '_foo' has been undefined or redefined. |
26-
| test.cpp:38:1:38:12 | #define _foo | Reserved identifier '_foo' has been undefined or redefined. |
1+
| test.cpp:2:1:2:12 | #undef errno | '#undef errno' uses a reserved name from the C99 standard library header <errno.h>. |
2+
| test.cpp:3:1:3:15 | #define errno 0 | '#define errno' uses a reserved name from the C99 standard library header <errno.h>. |
3+
| test.cpp:4:1:4:13 | #undef assert | '#undef assert' uses a reserved name from the C99 standard library header <assert.h>. |
4+
| test.cpp:5:1:5:27 | #define assert(condition) 0 | '#define assert' uses a reserved name from the C99 standard library header <assert.h>. |
5+
| test.cpp:7:1:7:15 | #undef __LINE__ | '#undef __LINE__' uses a name reserved for the C++14 implementation. |
6+
| test.cpp:8:1:8:18 | #define __LINE__ 0 | '#define __LINE__' uses a name reserved for the C++14 implementation. |
7+
| test.cpp:10:1:10:15 | #undef __FILE__ | '#undef __FILE__' uses a name reserved for the C++14 implementation. |
8+
| test.cpp:11:1:11:18 | #define __FILE__ 0 | '#define __FILE__' uses a name reserved for the C++14 implementation. |
9+
| test.cpp:13:1:13:15 | #undef __DATE__ | '#undef __DATE__' uses a name reserved for the C++14 implementation. |
10+
| test.cpp:14:1:14:18 | #define __DATE__ 0 | '#define __DATE__' uses a name reserved for the C++14 implementation. |
11+
| test.cpp:16:1:16:15 | #undef __TIME__ | '#undef __TIME__' uses a name reserved for the C++14 implementation. |
12+
| test.cpp:17:1:17:18 | #define __TIME__ 0 | '#define __TIME__' uses a name reserved for the C++14 implementation. |
13+
| test.cpp:19:1:19:15 | #undef __STDC__ | '#undef __STDC__' uses a name reserved for the C++14 implementation. |
14+
| test.cpp:20:1:20:18 | #define __STDC__ 0 | '#define __STDC__' uses a name reserved for the C++14 implementation. |
15+
| test.cpp:22:1:22:22 | #undef __STDC_HOSTED__ | '#undef __STDC_HOSTED__' uses a name reserved for the C++14 implementation. |
16+
| test.cpp:23:1:23:25 | #define __STDC_HOSTED__ 0 | '#define __STDC_HOSTED__' uses a name reserved for the C++14 implementation. |
17+
| test.cpp:25:1:25:18 | #undef __cplusplus | '#undef __cplusplus' uses a name reserved for the C++14 implementation. |
18+
| test.cpp:26:1:26:21 | #define __cplusplus 0 | '#define __cplusplus' uses a name reserved for the C++14 implementation. |
19+
| test.cpp:28:1:28:25 | #undef __STDCPP_THREADS__ | '#undef __STDCPP_THREADS__' uses a name reserved for the C++14 implementation. |
20+
| test.cpp:29:1:29:28 | #define __STDCPP_THREADS__ 0 | '#define __STDCPP_THREADS__' uses a name reserved for the C++14 implementation. |
21+
| test.cpp:31:1:31:19 | #undef __FUNCTION__ | '#undef __FUNCTION__' uses a name reserved for the C++14 implementation. |
22+
| test.cpp:32:1:32:22 | #define __FUNCTION__ 0 | '#define __FUNCTION__' uses a name reserved for the C++14 implementation. |
23+
| test.cpp:34:1:34:11 | #undef _Foo | '#undef _Foo' uses a name reserved for the C++14 implementation. |
24+
| test.cpp:35:1:35:12 | #define _Foo | '#define _Foo' uses a name reserved for the C++14 implementation. |
25+
| test.cpp:37:1:37:11 | #undef _foo | '#undef _foo' uses a name reserved for the C++14 implementation. |
26+
| test.cpp:38:1:38:12 | #define _foo | '#define _foo' uses a name reserved for the C++14 implementation. |

cpp/autosar/test/rules/A17-0-1/test.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#undef errno // NON_COMPLIANT
2-
#define errno 0 // NON_COMPLIANT
3-
1+
#include <errno.h>
2+
#undef errno // NON_COMPLIANT
3+
#define errno 0 // NON_COMPLIANT
44
#undef assert // NON_COMPLIANT
55
#define assert(condition) 0 // NON_COMPLIANT
66

@@ -54,4 +54,6 @@ void test_macros_are_invoked() {
5454
__cplusplus; // COMPLIANT
5555
__STDC_HOSTED__; // COMPLIANT
5656
__FUNCTION__; // COMPLIANT
57-
}
57+
}
58+
59+
#define str(x) 0 // NON_COMPLIANT

0 commit comments

Comments
 (0)