Skip to content

Commit e252fb3

Browse files
committed
Fix braced initialization detection in A8-5-3
1 parent bac2169 commit e252fb3

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- `A8-5-3` - `AvoidAutoWithBracedInitialization.ql`:
2+
- Fix regression where `auto x{0}` was no longer detected as a braced initialization with type `auto` with the latest CodeQL versions.
3+
- No longer falsely detect cases where braced initialization was not used, but where the inferred type would be `std::initializer_list`.

cpp/autosar/src/rules/A8-5-3/AvoidAutoWithBracedInitialization.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ from Variable v
2121
where
2222
not isExcluded(v, InitializationPackage::avoidAutoWithBracedInitializationQuery()) and
2323
v.getTypeWithAuto().getUnspecifiedType() instanceof AutoType and
24-
v.getType().getUnspecifiedType().(Class).hasQualifiedName("std", "initializer_list")
24+
v.getInitializer().isBraced()
2525
select v, "Variable " + v.getName() + " of type auto uses braced initialization."
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#include <initializer_list>
22

33
void test() {
4-
auto a1(1); // COMPLIANT
5-
auto a2{1}; // NON_COMPLIANT
6-
auto a3 = 1; // COMPLIANT
7-
auto a4 = {1}; // NON_COMPLIANT
8-
int a5 = {1}; // COMPLIANT
9-
const auto a6(1); // COMPLIANT
10-
const auto a7{1}; // NON_COMPLIANT
4+
auto a1(1); // COMPLIANT
5+
auto a2{1}; // NON_COMPLIANT
6+
auto a3 = 1; // COMPLIANT
7+
auto a4 = {1}; // NON_COMPLIANT
8+
int a5 = {1}; // COMPLIANT
9+
const auto a6(1); // COMPLIANT
10+
const auto a7{1}; // NON_COMPLIANT
11+
auto a8 = std::initializer_list<int>(); // COMPLIANT
1112
}

0 commit comments

Comments
 (0)