C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Draft 2: Error on out-of-bounds index

From: Levo D <levoplusplus_at_[hidden]>
Date: Fri, 29 Aug 2025 21:43:14 +0000
The goal of my proposal is to have all bounds be checked at compile time. If I were including containers, the check would be for all containers (and arrays).
I haven't seen "hardened preconditions," but glancing at P3471R0, it looks like it's a runtime check, which isn't my goal.

There isn't anything I could add to that. It'd be helpful if that proposal went through, since there might be a lot of changes inside a code base for access to be provably in bounds.
Off the top of my head, there might not be too many changes in my current one and one for containers.

The harder part is stating when a container shouldn't have a bounds check (unless I should explicitly name all the containers that should have it).
A map where people may want mapVar[-123] to return a value shouldn't be checked,
although I'm unsure if people want me to include a case for maps where we need to check if a key exists before using it that way.

Received on 2025-08-29 21:43:14