Skip to content

Disable GCC False array-bounds Warning #4704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

yehudamber
Copy link

When JSON_DIAGNOSTICS is set to 1, GCC might (depending on optimization level and the exact code) give an array-bounds warning about the basic_json::basic_json(CompatibleType&&) constructor, saying that basic_json::set_parents() might access a larger object than the storage allocated by to_json. That is not true, as the storage is only accessed according to the value type set in m_data.m_type by the constructing function, but GCC seems to not understand it.
This PR simply adds preprocessor directives around the call to set_parents to ignore the warning.

fixes #4657

@coveralls
Copy link

coveralls commented Mar 24, 2025

Coverage Status

coverage: 99.186%. remained the same
when pulling 931ecf9 on yehudamber:fix-4657
into 3a57039 on nlohmann:develop.

@nlohmann
Copy link
Owner

nlohmann commented Mar 24, 2025

PR #4701 should fix the CI issue. I'll ping you once it is merged to rebase this branch.

Signed-off-by: Yehuda Bernat <[email protected]>
Signed-off-by: Yehuda Bernat <[email protected]>
@gregmarr
Copy link
Contributor

gregmarr commented Apr 2, 2025

Has this been reported to GCC as a bug? It seems like this is something that could pop up anywhere, and if we try to fix it everywhere it appears, we're going to be sprinkling these pragmas all over the code.

@nlohmann nlohmann mentioned this pull request Apr 12, 2025
2 tasks
@nlohmann
Copy link
Owner

I agree with @gregmarr that this should be fixed by GCC and not suppressed here by the library.

@nlohmann nlohmann closed this Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

compile error when using gcc14
4 participants