-
Notifications
You must be signed in to change notification settings - Fork 1.9k
C++: Add predicates to support C++23 multidimensional subscript operators #21126
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
Open
jketema
wants to merge
6
commits into
github:main
Choose a base branch
from
jketema:subscript
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+113
−7
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
647d11a
C++: Add test for C++23 multidimensional subscript operators
jketema 3907fc7
C++: Add predicates to support multidimensional subscript operators
jketema e0f8b12
C++: Update expected test results
jketema 4c3fb0c
C++: Deprecate getArrayOffset/0
jketema 9ceb091
C++: Update predicate after `getAnArrayOffset/0` deprecation
jketema 72f1aa9
C++: Add change notes
jketema File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
cpp/ql/lib/change-notes/2026-01-08-multidimensional-subscript-operator-1.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| category: feature | ||
| --- | ||
| * Predicates `getArrayOffset/1` and `getAnArrayOffset` have been added to the `OverloadedArrayExpr` class to support C++23 multidimensional subscript operators. |
4 changes: 4 additions & 0 deletions
4
cpp/ql/lib/change-notes/2026-01-08-multidimensional-subscript-operator-2.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| category: deprecated | ||
| --- | ||
| * The `OverloadedArrayExpr::getArrayOffset/0` predicate has been deprecated. Use `OverloadedArrayExpr::getArrayOffset/1` and `OverloadedArrayExpr::getAnArrayOffset` instead. |
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
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
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
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
69 changes: 69 additions & 0 deletions
69
cpp/ql/test/library-tests/subscript_operator/PrintAST.expected
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| #-----| [CopyAssignmentOperator] __va_list_tag& __va_list_tag::operator=(__va_list_tag const&) | ||
| #-----| <params>: | ||
| #-----| getParameter(0): [Parameter] (unnamed parameter 0) | ||
| #-----| Type = [LValueReferenceType] const __va_list_tag & | ||
| #-----| [MoveAssignmentOperator] __va_list_tag& __va_list_tag::operator=(__va_list_tag&&) | ||
| #-----| <params>: | ||
| #-----| getParameter(0): [Parameter] (unnamed parameter 0) | ||
| #-----| Type = [RValueReferenceType] __va_list_tag && | ||
| test.cpp: | ||
| # 3| [CopyAssignmentOperator] S& S::operator=(S const&) | ||
| # 3| <params>: | ||
| #-----| getParameter(0): [Parameter] (unnamed parameter 0) | ||
| #-----| Type = [LValueReferenceType] const S & | ||
| # 3| [MoveAssignmentOperator] S& S::operator=(S&&) | ||
| # 3| <params>: | ||
| #-----| getParameter(0): [Parameter] (unnamed parameter 0) | ||
| #-----| Type = [RValueReferenceType] S && | ||
| # 5| [MemberFunction] int S::operator[](int, int) | ||
| # 5| <params>: | ||
| # 5| getParameter(0): [Parameter] i | ||
| # 5| Type = [IntType] int | ||
| # 5| getParameter(1): [Parameter] j | ||
| # 5| Type = [IntType] int | ||
| # 5| getEntryPoint(): [BlockStmt] { ... } | ||
| # 6| getStmt(0): [ReturnStmt] return ... | ||
| # 6| getExpr(): [ArrayExpr] access to array | ||
| # 6| Type = [IntType] int | ||
| # 6| ValueCategory = prvalue(load) | ||
| # 6| getArrayBase(): [ArrayExpr] access to array | ||
| # 6| Type = [ArrayType] int[2] | ||
| # 6| ValueCategory = lvalue | ||
| # 6| getArrayBase(): [ImplicitThisFieldAccess,PointerFieldAccess] xs | ||
| # 6| Type = [ArrayType] int[2][2] | ||
| # 6| ValueCategory = lvalue | ||
| # 6| getQualifier(): [ThisExpr] this | ||
| # 6| Type = [PointerType] S * | ||
| # 6| ValueCategory = prvalue(load) | ||
| # 6| getArrayOffset(): [VariableAccess] i | ||
| # 6| Type = [IntType] int | ||
| # 6| ValueCategory = prvalue(load) | ||
| #-----| getArrayBase().getFullyConverted(): [ArrayToPointerConversion] array to pointer conversion | ||
| #-----| Type = [PointerType] int(*)[2] | ||
| #-----| ValueCategory = prvalue | ||
| # 6| getArrayOffset(): [VariableAccess] j | ||
| # 6| Type = [IntType] int | ||
| # 6| ValueCategory = prvalue(load) | ||
| # 6| getArrayBase().getFullyConverted(): [ArrayToPointerConversion] array to pointer conversion | ||
| # 6| Type = [IntPointerType] int * | ||
| # 6| ValueCategory = prvalue | ||
| # 10| [TopLevelFunction] int foo(S) | ||
| # 10| <params>: | ||
| # 10| getParameter(0): [Parameter] s | ||
| # 10| Type = [Struct] S | ||
| # 10| getEntryPoint(): [BlockStmt] { ... } | ||
| # 11| getStmt(0): [ReturnStmt] return ... | ||
| # 11| getExpr(): [OverloadedArrayExpr] call to operator[] | ||
| # 11| Type = [IntType] int | ||
| # 11| ValueCategory = prvalue | ||
| # 11| getArrayBase(): [VariableAccess] s | ||
| # 11| Type = [Struct] S | ||
| # 11| ValueCategory = lvalue | ||
| # 11| getArrayOffset(0): [Literal] 1 | ||
| # 11| Type = [IntType] int | ||
| # 11| Value = [Literal] 1 | ||
| # 11| ValueCategory = prvalue | ||
| # 11| getArrayOffset(1): [Literal] 2 | ||
| # 11| Type = [IntType] int | ||
| # 11| Value = [Literal] 2 | ||
| # 11| ValueCategory = prvalue |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| semmle/code/cpp/PrintAST.ql |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // semmle-extractor-options: -std=c++23 | ||
|
|
||
| struct S { | ||
| int xs[2][2]; | ||
| int operator[](int i, int j) { | ||
| return xs[i][j]; | ||
| } | ||
| }; | ||
|
|
||
| int foo(S s) { | ||
| return s[1, 2]; | ||
| } |
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.
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.
The documentation comment "Gets the expression giving the nth index" could be clearer. Consider specifying that
nis 0-indexed (i.e., n=0 gives the first index, n=1 gives the second index, etc.) to make the usage more explicit for users.