This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
On 14 March 2018 at 23:27, Jonathan Wakely wrote: > Here's one way to generalize this idea. We could potentially replace > most of the lightweight __glibcxx_assert checks with this, to get > zero-overhead static checking at compile-time whenever possible (even > in constexpr functions) and have optional run-time assertions for the > remaining cases. Thinking about this some more, we probably don't want to do this for most __glibcxx_assert uses, because it's probably rare that we can statically detect most errors in something like std::vector::operator[]. I doubt we would catch many bugs that way, as most bugs would involve non-constant indices and vectors that have changed size dynamically at run-time. It *might* be useful in vector::front, vector::back, string::front, deque::front etc. to catch bugs where users do: std::string s; // ... someFunction(&s.front(), s.size()); It seems most valuable in constexpr functions (where we definitely expect constant arguments in many cases) and where run-time arguments will typically be constants, like in the attached patch for atomic objects.
Attachment:
patch.txt
Description: Text document
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |