-
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
base: main
Are you sure you want to change the base?
Conversation
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 adds support for C++23 multidimensional subscript operators, which allow operator[] to accept multiple indices (e.g., array[i, j] instead of array[i][j]). The PR updates the CodeQL library to handle this new language feature.
- Deprecates the
OverloadedArrayExpr::getArrayOffset/0predicate in favor of indexed access - Adds
getArrayOffset/1to retrieve a specific index by position, andgetAnArrayOffsetto retrieve any index - Updates existing code to use the new predicates
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| cpp/ql/lib/semmle/code/cpp/exprs/Call.qll | Adds new predicates getArrayOffset(int n) and getAnArrayOffset(), deprecates getArrayOffset() |
| cpp/ql/lib/semmle/code/cpp/PrintAST.qll | Updates AST printing to use indexed array offset predicates |
| cpp/ql/src/jsf/lib/section_4_21_Operators/AV_Rule_166.qll | Updates to check all array offsets are pure using getAnArrayOffset() |
| cpp/ql/test/library-tests/subscript_operator/test.cpp | Test case demonstrating C++23 multidimensional subscript operator syntax |
| cpp/ql/test/library-tests/subscript_operator/PrintAST.qlref | Test reference to PrintAST query |
| cpp/ql/test/library-tests/subscript_operator/PrintAST.expected | Expected AST output showing indexed array offsets |
| cpp/ql/test/library-tests/ir/ir/PrintAST.expected | Updated expected output to use getArrayOffset(0) |
| cpp/ql/lib/change-notes/2026-01-08-multidimensional-subscript-operator-1.md | Feature change note documenting new predicates |
| cpp/ql/lib/change-notes/2026-01-08-multidimensional-subscript-operator-2.md | Deprecation change note for old predicate |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| deprecated Expr getArrayOffset() { result = this.getArrayOffset(0) } | ||
|
|
||
| /** | ||
| * Gets the expression giving the nth index. |
Copilot
AI
Jan 8, 2026
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 n is 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.
| * Gets the expression giving the nth index. | |
| * Gets the expression giving the nth index, where `n` is 0-based | |
| * (that is, `n = 0` gives the first index, `n = 1` gives the second, etc.). |
This is supported out-of-the-box by the extractor.
See also https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2128r6.pdf
DCA is uneventful.