C++: Add direct and default initialization subclasses for ConstructorFieldInit

This commit is contained in:
Jeroen Ketema
2026-03-24 13:06:52 +01:00
parent cc99867969
commit 5aabd90eff
3 changed files with 77 additions and 52 deletions

View File

@@ -585,12 +585,15 @@ class ConstructorDelegationInit extends ConstructorBaseInit, @ctordelegatinginit
/**
* An initialization of a member variable performed as part of a
* constructor's explicit initializer list or implicit actions.
* constructor's initializer list or by default initialization.
*
* In the example below, member variable `b` is being initialized by
* constructor parameter `a`:
* constructor parameter `a`, and `c` is initialized by default
* initialization:
* ```
* struct S {
* int b;
* int c = 3;
* S(int a): b(a) {}
* } s(2);
* ```
@@ -616,6 +619,28 @@ class ConstructorFieldInit extends ConstructorInit, @ctorfieldinit {
override predicate mayBeGloballyImpure() { this.getExpr().mayBeGloballyImpure() }
}
/**
* An initialization of a member variable performed as part of a
* constructor's explicit initializer list.
*/
class ConstructorDirectFieldInit extends ConstructorFieldInit {
ConstructorDirectFieldInit() { exists(this.getChild(0)) }
override string getAPrimaryQlClass() { result = "ConstructorDirectFieldInit" }
}
/**
* An initialization of a member variable performed by default
* initialization.
*/
class ConstructorDefaultFieldInit extends ConstructorFieldInit {
ConstructorDefaultFieldInit() {
not exists(this.getChild(0)) and exists(this.getTarget().getInitializer())
}
override string getAPrimaryQlClass() { result = "ConstructorDefaultFieldInit" }
}
/**
* A call to a destructor of a base class or field as part of a destructor's
* compiler-generated actions.