Skip to content

Commit 5f738b3

Browse files
committed
Update message, add additional tests
1 parent fcbe4e7 commit 5f738b3

File tree

3 files changed

+70
-42
lines changed

3 files changed

+70
-42
lines changed
Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
1-
| test.c:2:1:2:23 | #define _RESERVED_MACRO | Macro '_RESERVED_MACRO' uses a reserved name beginning _ followed by an uppercase letter. |
2-
| test.c:6:1:6:27 | #define _not_reserved_MACRO | Macro '_not_reserved_MACRO' uses a name beginning with _ which is reserved in the ordinary and tag namespaces. |
3-
| test.c:11:8:11:9 | _s | Type '_s' uses a name beginning with _ which is reserved in the tag name space. |
4-
| test.c:15:6:15:7 | _f | Function '_f' uses a name beginning with _ which is reserved in the ordinary name space. |
5-
| test.c:19:7:19:12 | malloc | Function 'malloc' uses a reserved name from the C11 standard library header 'stdlib.h'. |
6-
| test.c:25:5:25:9 | errno | Global variable 'errno' uses a name reserved for a macro from the C11 standard library header 'errno.h'. |
7-
| test.c:25:5:25:9 | errno | Global variable 'errno' uses a reserved name from the C11 standard library header 'errno.h'. |
8-
| test.c:39:16:39:18 | log | Parameter 'log' uses a name reserved for a macro from the C11 standard library header 'tgmath.h'. |
9-
| test.c:43:5:43:16 | _Test_global | Global variable '_Test_global' uses a reserved name beginning _ followed by an uppercase letter. |
10-
| test.c:44:6:44:15 | _Test_func | Function '_Test_func' uses a reserved name beginning _ followed by an uppercase letter. |
11-
| test.c:45:9:45:19 | _Test_param | Parameter '_Test_param' uses a reserved name beginning _ followed by an uppercase letter. |
12-
| test.c:46:7:46:17 | _Test_local | Local variable '_Test_local' uses a reserved name beginning _ followed by an uppercase letter. |
13-
| test.c:47:10:47:27 | _Test_struct_local | Type '_Test_struct_local' uses a reserved name beginning _ followed by an uppercase letter. |
14-
| test.c:49:9:49:20 | _Test_member | Member variable '_Test_member' uses a reserved name beginning _ followed by an uppercase letter. |
15-
| test.c:52:8:52:19 | _Test_struct | Type '_Test_struct' uses a reserved name beginning _ followed by an uppercase letter. |
16-
| test.c:53:7:53:18 | _Test_member | Member variable '_Test_member' uses a reserved name beginning _ followed by an uppercase letter. |
17-
| test.c:55:1:56:3 | #define _TEST_MACRO x | Macro '_TEST_MACRO' uses a reserved name beginning _ followed by an uppercase letter. |
18-
| test.c:60:5:60:24 | __test_double_global | Global variable '__test_double_global' uses a reserved name beginning with __. |
19-
| test.c:61:6:61:23 | __test_double_func | Function '__test_double_func' uses a reserved name beginning with __. |
20-
| test.c:62:9:62:27 | __test_double_param | Parameter '__test_double_param' uses a reserved name beginning with __. |
21-
| test.c:63:7:63:25 | __test_double_local | Local variable '__test_double_local' uses a reserved name beginning with __. |
22-
| test.c:64:10:64:35 | __test_double_struct_local | Type '__test_double_struct_local' uses a reserved name beginning with __. |
23-
| test.c:65:9:65:28 | __test_double_member | Member variable '__test_double_member' uses a reserved name beginning with __. |
24-
| test.c:68:8:68:27 | __test_double_struct | Type '__test_double_struct' uses a reserved name beginning with __. |
25-
| test.c:69:7:69:26 | __test_double_member | Member variable '__test_double_member' uses a reserved name beginning with __. |
26-
| test.c:71:1:71:22 | #define __TEST_MACRO x | Macro '__TEST_MACRO' uses a reserved name beginning with __. |
27-
| test.c:78:5:78:22 | _test_lower_global | Global variable '_test_lower_global' uses a name beginning with _ which is reserved in the ordinary name space. |
28-
| test.c:79:6:79:21 | _test_lower_func | Function '_test_lower_func' uses a name beginning with _ which is reserved in the ordinary name space. |
29-
| test.c:88:8:88:19 | _test_struct | Type '_test_struct' uses a name beginning with _ which is reserved in the tag name space. |
30-
| test.c:91:1:92:3 | #define _test_macro x | Macro '_test_macro' uses a name beginning with _ which is reserved in the ordinary and tag namespaces. |
1+
| test.c:2:1:2:23 | #define _RESERVED_MACRO | Macro '_RESERVED_MACRO' declares a reserved name beginning _ followed by an uppercase letter. |
2+
| test.c:6:1:6:28 | #define _also_reserved_MACRO | Macro '_also_reserved_MACRO' declares a name beginning with _ which is reserved in the ordinary and tag namespaces. |
3+
| test.c:11:8:11:9 | _s | Type '_s' declares a name beginning with _ which is reserved in the tag name space. |
4+
| test.c:15:6:15:7 | _f | Function '_f' declares a name beginning with _ which is reserved in the ordinary name space. |
5+
| test.c:19:7:19:12 | malloc | Function 'malloc' declares a reserved name from the C11 standard library header 'stdlib.h'. |
6+
| test.c:25:5:25:9 | errno | Global variable 'errno' declares a name reserved for a macro from the C11 standard library header 'errno.h'. |
7+
| test.c:25:5:25:9 | errno | Global variable 'errno' declares a reserved name from the C11 standard library header 'errno.h'. |
8+
| test.c:39:16:39:18 | log | Parameter 'log' declares a name reserved for a macro from the C11 standard library header 'tgmath.h'. |
9+
| test.c:43:5:43:16 | _Test_global | Global variable '_Test_global' declares a reserved name beginning _ followed by an uppercase letter. |
10+
| test.c:44:6:44:15 | _Test_func | Function '_Test_func' declares a reserved name beginning _ followed by an uppercase letter. |
11+
| test.c:45:9:45:19 | _Test_param | Parameter '_Test_param' declares a reserved name beginning _ followed by an uppercase letter. |
12+
| test.c:46:7:46:17 | _Test_local | Local variable '_Test_local' declares a reserved name beginning _ followed by an uppercase letter. |
13+
| test.c:47:10:47:27 | _Test_struct_local | Type '_Test_struct_local' declares a reserved name beginning _ followed by an uppercase letter. |
14+
| test.c:49:9:49:20 | _Test_member | Member variable '_Test_member' declares a reserved name beginning _ followed by an uppercase letter. |
15+
| test.c:52:8:52:19 | _Test_struct | Type '_Test_struct' declares a reserved name beginning _ followed by an uppercase letter. |
16+
| test.c:53:7:53:18 | _Test_member | Member variable '_Test_member' declares a reserved name beginning _ followed by an uppercase letter. |
17+
| test.c:55:1:56:3 | #define _TEST_MACRO x | Macro '_TEST_MACRO' declares a reserved name beginning _ followed by an uppercase letter. |
18+
| test.c:60:5:60:24 | __test_double_global | Global variable '__test_double_global' declares a reserved name beginning with __. |
19+
| test.c:61:6:61:23 | __test_double_func | Function '__test_double_func' declares a reserved name beginning with __. |
20+
| test.c:62:9:62:27 | __test_double_param | Parameter '__test_double_param' declares a reserved name beginning with __. |
21+
| test.c:63:7:63:25 | __test_double_local | Local variable '__test_double_local' declares a reserved name beginning with __. |
22+
| test.c:64:10:64:35 | __test_double_struct_local | Type '__test_double_struct_local' declares a reserved name beginning with __. |
23+
| test.c:65:9:65:28 | __test_double_member | Member variable '__test_double_member' declares a reserved name beginning with __. |
24+
| test.c:68:8:68:27 | __test_double_struct | Type '__test_double_struct' declares a reserved name beginning with __. |
25+
| test.c:69:7:69:26 | __test_double_member | Member variable '__test_double_member' declares a reserved name beginning with __. |
26+
| test.c:71:1:71:22 | #define __TEST_MACRO x | Macro '__TEST_MACRO' declares a reserved name beginning with __. |
27+
| test.c:78:5:78:22 | _test_lower_global | Global variable '_test_lower_global' declares a name beginning with _ which is reserved in the ordinary name space. |
28+
| test.c:79:6:79:21 | _test_lower_func | Function '_test_lower_func' declares a name beginning with _ which is reserved in the ordinary name space. |
29+
| test.c:88:8:88:19 | _test_struct | Type '_test_struct' declares a name beginning with _ which is reserved in the tag name space. |
30+
| test.c:91:1:92:3 | #define _test_macro x | Macro '_test_macro' declares a name beginning with _ which is reserved in the ordinary and tag namespaces. |
31+
| test.c:97:5:97:10 | NDEBUG | Global variable 'NDEBUG' declares a name reserved for a macro from the C11 standard library header 'assert.h'. |
32+
| test.c:98:6:98:9 | EDOM | Function 'EDOM' declares a name reserved for a macro from the C11 standard library header 'errno.h'. |
33+
| test.c:99:9:99:14 | ERANGE | Parameter 'ERANGE' declares a name reserved for a macro from the C11 standard library header 'errno.h'. |
34+
| test.c:100:7:100:12 | NDEBUG | Local variable 'NDEBUG' declares a name reserved for a macro from the C11 standard library header 'assert.h'. |
35+
| test.c:101:10:101:15 | NDEBUG | Type 'NDEBUG' declares a name reserved for a macro from the C11 standard library header 'assert.h'. |
36+
| test.c:102:9:102:14 | NDEBUG | Member variable 'NDEBUG' declares a name reserved for a macro from the C11 standard library header 'assert.h'. |
37+
| test.c:105:8:105:13 | NDEBUG | Type 'NDEBUG' declares a name reserved for a macro from the C11 standard library header 'assert.h'. |
38+
| test.c:106:7:106:12 | NDEBUG | Member variable 'NDEBUG' declares a name reserved for a macro from the C11 standard library header 'assert.h'. |
39+
| test.c:108:1:109:3 | #define NDEBUG x | Macro 'NDEBUG' declares a name reserved for a macro from the C11 standard library header 'assert.h'. |

c/common/test/rules/declaredareservedidentifier/test.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#define _RESERVED_MACRO // NON_COMPLIANT
33
#endif /* _RESERVED_MACRO */
44

5-
#ifndef _not_reserved_MACRO
6-
#define _not_reserved_MACRO // COMPLIANT
7-
#endif /* _not_reserved_MACRO */
5+
#ifndef _also_reserved_MACRO
6+
#define _also_reserved_MACRO // NON_COMPLIANT
7+
#endif /* _not_reserved_MACRO */
88

99
static const int INT_LIMIT_MAX = 12000; // COMPLIANT future library directions
1010

@@ -89,4 +89,22 @@ struct _test_struct { // NON_COMPLIANT - _ is reserved in the tag name space
8989
int _test; // COMPLIANT - _ is not reserved in the member name space
9090
};
9191
#define _test_macro \
92-
x // NON_COMPLIANT - _ is reserved for macro names (otherwise you couldn't )
92+
x // NON_COMPLIANT - _ is reserved for for file scope names and so cannot be
93+
// used as a macro name
94+
95+
/* Identify names reserved as a macro. */
96+
97+
int NDEBUG; // NON_COMPLIANT - NDEBUG is reserved as a macro name
98+
void EDOM( // NON_COMPLIANT - EDOM is reserved as a macro name
99+
int ERANGE) { // NON_COMPLIANT - ERANGE is reserved as a macro name
100+
int NDEBUG; // NON_COMPLIANT - NDEBUG is reserved as a macro name
101+
struct NDEBUG { // NON_COMPLIANT - NDEBUG is reserved as a macro name
102+
int NDEBUG; // NON_COMPLIANT - NDEBUG is reserved as a macro name
103+
};
104+
}
105+
struct NDEBUG { // NON_COMPLIANT - NDEBUG is reserved as a macro name
106+
int NDEBUG; // NON_COMPLIANT - NDEBUG is reserved as a macro name
107+
};
108+
#define NDEBUG \
109+
x // NON_COMPLIANT - NDEBUG is reserved as a macro name for the standard
110+
// library

cpp/common/src/codingstandards/cpp/rules/declaredareservedidentifier/DeclaredAReservedIdentifier.qll

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,30 +147,31 @@ query predicate problems(Element m, string message) {
147147
name.regexpMatch("__.*") and
148148
// Exclude this macro which is intended to be implemented by the user
149149
not name = "__STDC_WANT_LIB_EXT1__" and
150-
reason = "uses a reserved name beginning with __"
150+
reason = "declares a reserved name beginning with __"
151151
or
152152
name.regexpMatch("_[A-Z].*") and
153-
reason = "uses a reserved name beginning _ followed by an uppercase letter"
153+
reason = "declares a reserved name beginning _ followed by an uppercase letter"
154154
or
155155
// > All identifiers that begin with an underscore are always reserved for use as identifiers
156156
// > with file scope in both the ordinary and tag name spaces.
157157
name.regexpMatch("_([^A-Z_].*)?") and
158158
scope = FileScope() and
159159
cNameSpace = [OrdinaryNameSpace().(TCNameSpace), TagNameSpace()] and
160-
reason = "uses a name beginning with _ which is reserved in the " + cNameSpace + " name space"
160+
reason =
161+
"declares a name beginning with _ which is reserved in the " + cNameSpace + " name space"
161162
or
162163
name.regexpMatch("_([^A-Z_].*)?") and
163164
scope = MacroScope() and
164165
cNameSpace = MacroNameSpace() and
165-
reason = "uses a name beginning with _ which is reserved in the ordinary and tag namespaces"
166+
reason = "declares a name beginning with _ which is reserved in the ordinary and tag namespaces"
166167
or
167168
// > Each macro name in any of the following subclauses (including the future library
168169
// > directions) is reserved for use as specified if any of its associated headers is included;
169170
// > unless explicitly stated otherwise (see 7.1.4).
170171
exists(string header |
171172
TargetedCLibrary::hasMacroName(header, name, _) and
172173
reason =
173-
"uses a name reserved for a macro from the " + TargetedCLibrary::getName() +
174+
"declares a name reserved for a macro from the " + TargetedCLibrary::getName() +
174175
" standard library header '" + header + "'"
175176
)
176177
or
@@ -201,7 +202,7 @@ query predicate problems(Element m, string message) {
201202
|
202203
hasExternalLinkage(m) and
203204
reason =
204-
"uses a reserved name from the " + TargetedCLibrary::getName() +
205+
"declares a reserved name from the " + TargetedCLibrary::getName() +
205206
" standard library header '" + header + "'"
206207
)
207208
or
@@ -228,12 +229,12 @@ query predicate problems(Element m, string message) {
228229
scope = MacroScope()
229230
) and
230231
reason =
231-
"uses a reserved name from the " + TargetedCLibrary::getName() +
232+
"declares a reserved name from the " + TargetedCLibrary::getName() +
232233
" standard library header '" + header + "'"
233234
)
234235
or
235236
// C11 6.4.1/2
236237
Keywords::isKeyword(name) and
237-
reason = "it is a C11 keyword"
238+
reason = "declares a reserved name which is a C11 keyword"
238239
)
239240
}

0 commit comments

Comments
 (0)