mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Designated initialization with ranges would not error on overflow by 1.
This commit is contained in:
@@ -48,6 +48,7 @@
|
||||
- `String.tokenize_all` would yield one too many empty tokens at the end.
|
||||
- `String.replace` no longer depends on `String.split`.
|
||||
- Fix the case where `\u<unicode char>` could crash the compiler on some platforms.
|
||||
- Designated initialization with ranges would not error on overflow by 1.
|
||||
|
||||
### Stdlib changes
|
||||
- Add `ThreadPool` join function to wait for all threads to finish in the pool without destroying the threads.
|
||||
|
||||
@@ -1377,10 +1377,10 @@ static Type *sema_find_type_of_element(SemaContext *context, Type *type, Designa
|
||||
*did_report_error = true;
|
||||
return NULL;
|
||||
}
|
||||
if (end_index > (ArrayIndex)len)
|
||||
if (end_index >= (ArrayIndex)len)
|
||||
{
|
||||
*did_report_error = true;
|
||||
SEMA_ERROR(element->index_expr, "The index may must be less than the array length (which was %llu).", (unsigned long long)len);
|
||||
SEMA_ERROR(element->index_end_expr, "The index must be less than the array length (which was %llu).", (unsigned long long)len);
|
||||
return NULL;
|
||||
}
|
||||
element->index_end = end_index;
|
||||
|
||||
16
test/test_suite/bitstruct/designated_init_range_overflow.c3
Normal file
16
test/test_suite/bitstruct/designated_init_range_overflow.c3
Normal file
@@ -0,0 +1,16 @@
|
||||
enum Row : inline int { A, B, C, D, E, F }
|
||||
|
||||
int[3][6] m = {
|
||||
[Row.E] = {
|
||||
[0..3] = 1, // #error: The index must be less than the array length (which was 3)
|
||||
},
|
||||
[Row.F] = {
|
||||
[1] = 2,
|
||||
},
|
||||
};
|
||||
|
||||
fn int main()
|
||||
{
|
||||
(void)m;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user