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

Warning when building with NDEBUG #1621

Closed
L0PiTaL opened this issue Sep 27, 2022 · 3 comments · Fixed by #1622
Closed

Warning when building with NDEBUG #1621

L0PiTaL opened this issue Sep 27, 2022 · 3 comments · Fixed by #1622

Comments

@L0PiTaL
Copy link
Contributor

L0PiTaL commented Sep 27, 2022

Describe the bug
The compiler emits a warning when building with NDEBUG, due to expanding NNI_ASSERT to (0)

Expected behavior
No warnings

Actual Behavior
Warnings emited

To Reproduce
Just build the lib in release mode (or with NDEBUG set)

@ori-d
Copy link

ori-d commented Oct 9, 2022

I think this can be replaced with just emty define like
#define NNI_ASSERT(x)
That's all.

@L0PiTaL
Copy link
Contributor Author

L0PiTaL commented Oct 11, 2022

@ori-d
yes, there are a lot of ways to fix this. The PR is just one of them, which doesn't alter the current behavior, which is just to introduce a (0) instruction (which leads to a no-op). It just silences the diagnostic caused by this instruction.

By the way, with your fix, I think that it silences the diagnostic "empty instruction", but it would emit another diagnostic, "empty statement":
NNI_ASSERT(whatever); //Note the last semicolon, so NNI_ASSERT() can be treated as a "normal" function

would be expanded to:
; //nothing, but the semicolon remains

which now emits the "empty statement" diagnostic.
While with the solution in the PR, it expands to:
((void)(0));

which is a silenced empty instruction (so no diagnostic for this one, as it is silenced), and also not an empty statement (so it neither emits the other diagnostic).

@gdamore
Copy link
Contributor

gdamore commented Oct 17, 2022

#1622 fixes this.

You can't elide away the (0) ... because it may be used in a context where we have to have a valid statement.

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 a pull request may close this issue.

3 participants