Repository navigation
fix(cpp1): support empty and multi-argument indexing - #483
Conversation
I'll have to enhance https://github.com/modern-cmake/cppfront for this. |
|
See the generated test passing at https://cpp2.godbolt.org/z/PfoWWqznG in C++23. |
|
One question would be how the range checker can be extended to multiple dimensions. I do not know the standard proposal for this therefore I ask the question: How does the c++ standard defines the size operator for multi dimensional arrays? Can we use this mechanism to check the range of other dimensions? |
| if ( | ||
| flag_safe_subscripts | ||
| && i->op->type() == lexeme::LeftBracket | ||
| && std::ssize(i->expr_list->expressions) == 1 |
There was a problem hiding this comment.
Maybe add a TODO, that this needs to be extended for multiple dimensions.
There was a problem hiding this comment.
I think that perhaps the correct thing to do
is to only avoid cpp2::assert_in_bounds when there are no index arguments,
and add a multi-dimensional overload for cpp2::assert_in_bounds that doesn't assert.
Then someone versed in std::mdspan can just add an overload for it that asserts.
There was a problem hiding this comment.
Thanks! I think it's fine to do only single-dimensional bounds checks for the time being -- it will be quite a while before multidimensional is actually usable/used in the field.
There's none. |
|
Ok thanks for applying my remarks.
I had a look at cpp2::assert_in_bounds. Out of my had, one option would be: I have not tested this. The increment of dim in the expansion is kind of hacky. Here we would assume that there is a Do you want to pursue such an implementation or should we leave it. I you want I can try and implement it. |
|
That doesn't work for It could work for a container of containers Without actual use-cases, it's hard to argue in favor of an overload that asserts. |
| if (!term.expr_list) | ||
| { | ||
| error("subscript expression [ ] must not be empty (if you were trying to name a C-style array type, use 'std::array' instead)"); | ||
| next(); |
There was a problem hiding this comment.
We should still have an error here though, should we? Like the one for ( at line 4181 below.
Signed-off-by: Herb Sutter <herb.sutter@gmail.com>
* fix(cpp1): support empty and multi-argument indexing * Make error message for `[` arg case symmetric with `(` arg case Signed-off-by: Herb Sutter <herb.sutter@gmail.com> --------- Signed-off-by: Herb Sutter <herb.sutter@gmail.com> Co-authored-by: Herb Sutter <herb.sutter@gmail.com>


Resolves #482.
Partially addresses #387 (
operator[]).The added test requires C++23.
Testing summary.
Acknowledgements.