Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7c7d0ac

Browse filesBrowse files
authored
Merge pull request #608 from github/lcartey/a7-1-2
A7-1-2: Exclude generated variables and variables in uninstantiated templates
2 parents 7644032 + d8986c9 commit 7c7d0ac
Copy full SHA for 7c7d0ac

File tree

Expand file treeCollapse file tree

5 files changed

+46
-26
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+46
-26
lines changed
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A7-1-2` - `VariableMissingConstexpr.ql`:
2+
- Fixes #607. Remove false positives for compiler generated variables and in uninstantiated templates

‎cpp/autosar/src/rules/A7-1-2/VariableMissingConstexpr.ql

Copy file name to clipboardExpand all lines: cpp/autosar/src/rules/A7-1-2/VariableMissingConstexpr.ql
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,9 @@ where
6262
// Not assigned by a user in a constructor
6363
not exists(ConstructorFieldInit cfi | cfi.getTarget() = v and not cfi.isCompilerGenerated()) and
6464
// Ignore union members
65-
not v.getDeclaringType() instanceof Union
66-
select v, "Variable " + v.getName() + " could be marked 'constexpr'."
65+
not v.getDeclaringType() instanceof Union and
66+
// Exclude variables in uninstantiated templates, as they may be incomplete
67+
not v.isFromUninstantiatedTemplate(_) and
68+
// Exclude compiler generated variables, which are not user controllable
69+
not v.isCompilerGenerated()
70+
select v, "Variable '" + v.getName() + "' could be marked 'constexpr'."

‎cpp/autosar/test/rules/A7-1-2/FunctionMissingConstexpr.expected

Copy file name to clipboardExpand all lines: cpp/autosar/test/rules/A7-1-2/FunctionMissingConstexpr.expected
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@
1010
| test.cpp:162:3:162:26 | VariantMemberInitialized | VariantMemberInitialized function could be marked as 'constexpr'. |
1111
| test.cpp:163:3:163:26 | VariantMemberInitialized | VariantMemberInitialized function could be marked as 'constexpr'. |
1212
| test.cpp:190:3:190:22 | VariantMemberNotInit | VariantMemberNotInit function could be marked as 'constexpr'. |
13+
| test.cpp:269:26:269:26 | init | init function could be marked as 'constexpr'. |
14+
| test.cpp:269:26:269:29 | init | init function could be marked as 'constexpr'. |
15+
| test.cpp:271:26:271:26 | init | init function could be marked as 'constexpr'. |
16+
| test.cpp:277:6:277:32 | test_template_instantiation | test_template_instantiation function could be marked as 'constexpr'. |
+23-23Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
| test.cpp:4:5:4:6 | g1 | Variable g1 could be marked 'constexpr'. |
2-
| test.cpp:6:5:6:6 | g2 | Variable g2 could be marked 'constexpr'. |
3-
| test.cpp:13:14:13:15 | lc | Variable lc could be marked 'constexpr'. |
4-
| test.cpp:15:14:15:16 | lca | Variable lca could be marked 'constexpr'. |
5-
| test.cpp:23:15:23:17 | lc2 | Variable lc2 could be marked 'constexpr'. |
6-
| test.cpp:25:15:25:18 | lc2a | Variable lc2a could be marked 'constexpr'. |
7-
| test.cpp:41:14:41:15 | l2 | Variable l2 could be marked 'constexpr'. |
8-
| test.cpp:44:16:44:17 | lc | Variable lc could be marked 'constexpr'. |
9-
| test.cpp:45:17:45:19 | lc2 | Variable lc2 could be marked 'constexpr'. |
10-
| test.cpp:55:7:55:8 | m2 | Variable m2 could be marked 'constexpr'. |
11-
| test.cpp:130:7:130:8 | m1 | Variable m1 could be marked 'constexpr'. |
12-
| test.cpp:141:7:141:8 | m1 | Variable m1 could be marked 'constexpr'. |
13-
| test.cpp:221:7:221:8 | l1 | Variable l1 could be marked 'constexpr'. |
14-
| test.cpp:235:7:235:8 | l6 | Variable l6 could be marked 'constexpr'. |
15-
| test.cpp:237:7:237:8 | l8 | Variable l8 could be marked 'constexpr'. |
16-
| test.cpp:240:7:240:9 | l10 | Variable l10 could be marked 'constexpr'. |
17-
| test.cpp:243:7:243:9 | l12 | Variable l12 could be marked 'constexpr'. |
18-
| test.cpp:248:7:248:9 | l15 | Variable l15 could be marked 'constexpr'. |
19-
| test.cpp:250:7:250:9 | l16 | Variable l16 could be marked 'constexpr'. |
20-
| test.cpp:251:7:251:9 | l17 | Variable l17 could be marked 'constexpr'. |
21-
| test.cpp:257:7:257:9 | l21 | Variable l21 could be marked 'constexpr'. |
22-
| test.cpp:262:7:262:9 | l24 | Variable l24 could be marked 'constexpr'. |
23-
| test.cpp:263:7:263:9 | l25 | Variable l25 could be marked 'constexpr'. |
1+
| test.cpp:4:5:4:6 | g1 | Variable 'g1' could be marked 'constexpr'. |
2+
| test.cpp:6:5:6:6 | g2 | Variable 'g2' could be marked 'constexpr'. |
3+
| test.cpp:13:14:13:15 | lc | Variable 'lc' could be marked 'constexpr'. |
4+
| test.cpp:15:14:15:16 | lca | Variable 'lca' could be marked 'constexpr'. |
5+
| test.cpp:23:15:23:17 | lc2 | Variable 'lc2' could be marked 'constexpr'. |
6+
| test.cpp:25:15:25:18 | lc2a | Variable 'lc2a' could be marked 'constexpr'. |
7+
| test.cpp:41:14:41:15 | l2 | Variable 'l2' could be marked 'constexpr'. |
8+
| test.cpp:44:16:44:17 | lc | Variable 'lc' could be marked 'constexpr'. |
9+
| test.cpp:45:17:45:19 | lc2 | Variable 'lc2' could be marked 'constexpr'. |
10+
| test.cpp:55:7:55:8 | m2 | Variable 'm2' could be marked 'constexpr'. |
11+
| test.cpp:130:7:130:8 | m1 | Variable 'm1' could be marked 'constexpr'. |
12+
| test.cpp:141:7:141:8 | m1 | Variable 'm1' could be marked 'constexpr'. |
13+
| test.cpp:221:7:221:8 | l1 | Variable 'l1' could be marked 'constexpr'. |
14+
| test.cpp:235:7:235:8 | l6 | Variable 'l6' could be marked 'constexpr'. |
15+
| test.cpp:237:7:237:8 | l8 | Variable 'l8' could be marked 'constexpr'. |
16+
| test.cpp:240:7:240:9 | l10 | Variable 'l10' could be marked 'constexpr'. |
17+
| test.cpp:243:7:243:9 | l12 | Variable 'l12' could be marked 'constexpr'. |
18+
| test.cpp:248:7:248:9 | l15 | Variable 'l15' could be marked 'constexpr'. |
19+
| test.cpp:250:7:250:9 | l16 | Variable 'l16' could be marked 'constexpr'. |
20+
| test.cpp:251:7:251:9 | l17 | Variable 'l17' could be marked 'constexpr'. |
21+
| test.cpp:257:7:257:9 | l21 | Variable 'l21' could be marked 'constexpr'. |
22+
| test.cpp:262:7:262:9 | l24 | Variable 'l24' could be marked 'constexpr'. |
23+
| test.cpp:263:7:263:9 | l25 | Variable 'l25' could be marked 'constexpr'. |

‎cpp/autosar/test/rules/A7-1-2/test.cpp

Copy file name to clipboardExpand all lines: cpp/autosar/test/rules/A7-1-2/test.cpp
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,14 @@ constexpr void fp_reported_in_466(int p) {
264264
// compile time constant
265265
int l26 =
266266
add4(1, l3); // COMPLIANT - l3 is not compile time constant on all paths
267-
}
267+
}
268+
269+
template <typename T> T *init(T **t) {}
270+
271+
template <typename T> T *init() {
272+
T *t = nullptr; // COMPLIANT - initialized below
273+
init(&t); // Init is ignored in uninitialized template
274+
return t;
275+
}
276+
277+
void test_template_instantiation() { int *t = init<int>(); }

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.