Skip to content
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

Silence assert redefinition warning #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

laustam
Copy link
Contributor

@laustam laustam commented Jun 25, 2024

Currently, every test run using make (for example: make testall) causes two compilation warnings. These occur due to the redefinition of the assert macro. On my machine (Mac M1), these warnings look something like this:

tests/testutil.h:62:9: warning: '__assert' macro redefined [-Wmacro-redefined]
#define __assert(c) do { \
        ^
tests/testutil.h:70:9: warning: 'assert' macro redefined [-Wmacro-redefined]
#define assert(c) __assert(c);
        ^

Since these warnings do not indicate anything about students' code, I suggest that we silence these so as not to confuse students. This can be done by using the #pragma directive, as implemented in this PR.

Here is a short description of each of the #pragma directives used in this PR:

  • #pragma clang diagnostic push: This directive saves the current state of all diagnostic settings. It's used to create a stack of diagnostic states so that temporary changes can be made to the diagnostic settings and then revert back to the previous state.

  • #pragma clang diagnostic ignored "-Wmacro-redefined": This directive tells the Clang compiler to ignore the specific warning identified by -Wmacro-redefined. This is exactly what is triggered by the assert redefinition, so we want to silence this.

  • #pragma clang diagnostic pop: After the block of code where the redefinition warning is suppressed, this directive restores the previous state of the diagnostic settings that were saved by #pragma clang diagnostic push. This ensures that any changes to the diagnostic settings are only temporary and do not affect the rest of the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant