-
Notifications
You must be signed in to change notification settings - Fork 1.7k
C++: add predicate to distinguish designator-based initializations #19329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
a3371dc
to
caa2fff
Compare
caa2fff
to
cc49cfc
Compare
cc49cfc
to
15fe2fb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces predicates to distinguish designator-based initializations from positional ones for struct/union fields and array elements in C++.
- Added isDesignatorInit() predicates
- Updated change notes to document the new feature
Files not reviewed (8)
- cpp/downgrades/2e2d805ef93d060b813403cb9b51dc72455a4c68/aggregate_array_init.ql: Language not supported
- cpp/downgrades/2e2d805ef93d060b813403cb9b51dc72455a4c68/aggregate_field_init.ql: Language not supported
- cpp/downgrades/2e2d805ef93d060b813403cb9b51dc72455a4c68/upgrade.properties: Language not supported
- cpp/ql/lib/semmle/code/cpp/exprs/Literal.qll: Language not supported
- cpp/ql/lib/semmlecode.cpp.dbscheme: Language not supported
- cpp/ql/lib/upgrades/0f0a390468a5eb43d1dc72937c028070b106bf53/aggregate_array_init.ql: Language not supported
- cpp/ql/lib/upgrades/0f0a390468a5eb43d1dc72937c028070b106bf53/aggregate_field_init.ql: Language not supported
- cpp/ql/lib/upgrades/0f0a390468a5eb43d1dc72937c028070b106bf53/upgrade.properties: Language not supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor comments on the QLDoc, otherwise LGTM
* This can be used to distinguish explicitly designated initializations from | ||
* implicit positional ones. | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* This can be used to distinguish explicitly designated initializations from | |
* implicit positional ones. | |
* |
* - `.x = 1` is a designator init, therefore `isDesignatorInit(x, 0)` holds. | ||
* - `2` is a positional init for `.y`, therefore `isDesignatorInit(y, 1)` does **not** hold. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* - `.x = 1` is a designator init, therefore `isDesignatorInit(x, 0)` holds. | |
* - `2` is a positional init for `.y`, therefore `isDesignatorInit(y, 1)` does **not** hold. | |
* - `.x = 1` uses a designator, therefore `hasDesignator(x, 0)` holds. | |
* - `2` is positional for `.y`, therefore `hasDesignator(y, 1)` does not hold. |
|
||
/** | ||
* Holds if the `position`-th initialization of `field` in this aggregate initializer | ||
* uses a designator (e.g., `.x =`, `[42] =`) rather than a positional initializer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* uses a designator (e.g., `.x =`, `[42] =`) rather than a positional initializer. | |
* uses a designated (e.g., `.x = ...`) rather than a positional initializer. |
* - `[0] = 1` is a designator init, therefore `isDesignatorInit(0, 0)` holds. | ||
* - `2` is a positional init for `x[1]`, therefore `isDesignatorInit(1, 1)` does **not** hold. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* - `[0] = 1` is a designator init, therefore `isDesignatorInit(0, 0)` holds. | |
* - `2` is a positional init for `x[1]`, therefore `isDesignatorInit(1, 1)` does **not** hold. | |
* - `[0] = 1` uses a designator, therefore `hasDesignator(0, 0)` holds. | |
* - `2` is positional for `x[1]`, therefore `hasDesignator(1, 1)` does not hold. |
--- | ||
category: feature | ||
--- | ||
* Introduced `isDesignatorInit()` predicates to distinguish between designator-based and positional initializations for both struct/union fields and array elements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Introduced `isDesignatorInit()` predicates to distinguish between designator-based and positional initializations for both struct/union fields and array elements. | |
* Introduced `hasDesignator()` predicates to distinguish between designated and positional initializations for both struct/union fields and array elements. |
* - `.x = 1` is a designator init, therefore `isDesignatorInit(x, 0)` holds. | ||
* - `2` is a positional init for `.y`, therefore `isDesignatorInit(y, 1)` does **not** hold. | ||
*/ | ||
predicate isDesignatorInit(Field field, int position) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
predicate isDesignatorInit(Field field, int position) { | |
predicate hasDesignator(Field field, int position) { |
* Holds if the `position`-th initialization of the array element at `elementIndex` | ||
* in this aggregate initializer uses a designator (e.g., `[0] = ...`) rather than | ||
* an implicit positional initializer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Holds if the `position`-th initialization of the array element at `elementIndex` | |
* in this aggregate initializer uses a designator (e.g., `[0] = ...`) rather than | |
* an implicit positional initializer. | |
* Holds if the `position`-th initialization of the array element at `elementIndex` | |
* in this aggregate initializer uses a designated (e.g., `[0] = ...`) rather than | |
* an positional initializer. |
* - `[0] = 1` is a designator init, therefore `isDesignatorInit(0, 0)` holds. | ||
* - `2` is a positional init for `x[1]`, therefore `isDesignatorInit(1, 1)` does **not** hold. | ||
*/ | ||
predicate isDesignatorInit(int elementIndex, int position) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
predicate isDesignatorInit(int elementIndex, int position) { | |
predicate hasDesignator(int elementIndex, int position) { |
Introduced isDesignatorInit() predicates to distinguish between designator-based and positional initializations for both struct\union fields and array elements.