Add GLIBCXX_ASSERTIONS to recommended compiler flags#158
Draft
Ryanf55 wants to merge 1 commit intocpp-best-practices:masterfrom
Draft
Add GLIBCXX_ASSERTIONS to recommended compiler flags#158Ryanf55 wants to merge 1 commit intocpp-best-practices:masterfrom
Ryanf55 wants to merge 1 commit intocpp-best-practices:masterfrom
Conversation
Signed-off-by: Ryan Friedman <ryanfriedman5410+github@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
-Weverythingand compile in clang, it's not caught.I figured out you can enable bounds checking on bracket access with
GLIBCXX_ASSERTIONShttps://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.