Add GLIBCXX_ASSERTIONS to recommended compiler flags #158
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When migrating legacy code from
uint8_t my_arr[N]
tostd::array<uint8_t, N>
, there are places where bracket access is used. This does not perform bounds checking, even at compile time.For example, you could construct an array with 6 elements, then access element 42 at runtime with no errors, even with all the flags enabled that are currently recommended.
https://godbolt.org/z/3KWqe1vbs
Even if you set
-Weverything
and compile in clang, it's not caught.I figured out you can enable bounds checking on bracket access with
GLIBCXX_ASSERTIONS
https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros.html
There are runtime costs with bounds checking, so it should not be enabled in production, however this would be great flag to add to a debug build that is tested in CI.
With this enabled in debug mode, you seem to get the best of both worlds.