C++: add predicate to distinguish designator-based initializations#19329
Merged
C++: add predicate to distinguish designator-based initializations#19329
Conversation
a3371dc to
caa2fff
Compare
caa2fff to
cc49cfc
Compare
cc49cfc to
15fe2fb
Compare
Contributor
There was a problem hiding this comment.
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
jketema
previously approved these changes
Apr 17, 2025
Contributor
jketema
left a comment
There was a problem hiding this comment.
Some minor comments on the QLDoc, otherwise LGTM
Comment on lines
+223
to
+225
| * This can be used to distinguish explicitly designated initializations from | ||
| * implicit positional ones. | ||
| * |
Contributor
There was a problem hiding this comment.
Suggested change
| * This can be used to distinguish explicitly designated initializations from | |
| * implicit positional ones. | |
| * |
Comment on lines
+231
to
+232
| * - `.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. |
Contributor
There was a problem hiding this comment.
Suggested change
| * - `.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. |
Contributor
There was a problem hiding this comment.
Suggested change
| * uses a designator (e.g., `.x =`, `[42] =`) rather than a positional initializer. | |
| * uses a designated (e.g., `.x = ...`) rather than a positional initializer. |
Comment on lines
+340
to
+341
| * - `[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. |
Contributor
There was a problem hiding this comment.
Suggested change
| * - `[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. |
jketema
reviewed
Apr 17, 2025
| --- | ||
| category: feature | ||
| --- | ||
| * Introduced `isDesignatorInit()` predicates to distinguish between designator-based and positional initializations for both struct/union fields and array elements. No newline at end of file |
Contributor
There was a problem hiding this comment.
Suggested change
| * 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. |
jketema
reviewed
Apr 17, 2025
| * - `.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) { |
Contributor
There was a problem hiding this comment.
Suggested change
| predicate isDesignatorInit(Field field, int position) { | |
| predicate hasDesignator(Field field, int position) { |
jketema
reviewed
Apr 17, 2025
Comment on lines
+332
to
+334
| * 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. |
Contributor
There was a problem hiding this comment.
Suggested change
| * 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. |
jketema
reviewed
Apr 17, 2025
| * - `[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) { |
Contributor
There was a problem hiding this comment.
Suggested change
| predicate isDesignatorInit(int elementIndex, int position) { | |
| predicate hasDesignator(int elementIndex, int position) { |
jketema
approved these changes
Apr 17, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduced isDesignatorInit() predicates to distinguish between designator-based and positional initializations for both struct\union fields and array elements.