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

[Build] Stricter compiler warning settings #29209

Open
rojer opened this issue Sep 13, 2023 · 3 comments
Open

[Build] Stricter compiler warning settings #29209

rojer opened this issue Sep 13, 2023 · 3 comments

Comments

@rojer
Copy link
Contributor

rojer commented Sep 13, 2023

Build issue(s)

It's not a bug as such, rather a suggestion/discussion. I'm a relative newcomer to the project, currently busy integrating CHIP/Matter support into our product line. In our environment we build with stricter compiler warnings, so I had to adapt.
In my opinion, some of them might be useful tot he project (and as an added benefit to us, we won't have to suppress warnings and patch sources). We compile with -Wextra, but specifically I am talking about:

  1. -Wundef - I find it extremely useful. I actually got most of the CHIP to compile with -Wundef with only a minor change (Convert if __ZEPHYR__ to if defined(__ZEPHYR__) #29172). It helped me a lot during porting, since it exposed the macros I had to define, instead of just assuming false value. I think any project would benefit from -Wundef. For example, it exposed a minor bug.
  2. -Wunused-parameter - I find it helpful to have compiler remind that an argument passed to a function is not used. Sometimes it leads to reconsidering the function signature to get rid of the paramter, and in legitimate cases it can be be easily cast to void or annotated with __attribute__((unused)) (usually via a macro).

My proposal is thus to use -Wextra, at least for core components (as of today it already works, at least with clang-15), or at least add -Wundef which seems to be clearly useful. -Wunused-parameter is debatable but also a nice-to-have, in my opinion.

Platform

all

Anything else?

No response

@bzbarsky-apple
Copy link
Contributor

-Wextra is enabled by default in our CI. See

It looks like -Wextra does not imply -Wundef, at least per https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-W. Turning that on does seem useful.

-Wextra does imply -Wunused-parameter if we are also using -Wall, as we are, but then it's explicitly turned off at

"-Wno-unused-parameter",
. Looks like there are a lot of failures for this one, especially for methods that are returning "not implemented" or are otherwise optional-to-do-anything-in stubs. Annotating all the arguments to those one at a time as unused would be a pain; I suspect that to enable -Wunused-parameter we would want some way to annotate "this method uses none of its parameters".

@bzbarsky-apple
Copy link
Contributor

bzbarsky-apple commented Sep 13, 2023

I just tried enabling -Wundef and it fails with all sort of errors. Some of them seem pretty straightforward to fix, but a few look complicated:

@rojer
Copy link
Contributor Author

rojer commented Sep 13, 2023

@bzbarsky-apple wow, thanks for the detailed response! you are correct, -Wundef is not part of -Wextra, we add it explicitly (i did it way back when and have since forgotten about it). our full warning settings are -Wall -Wextra -Wundef -Werror, i find it a nice combo.
i see you are well on the way to enabling -Wundef - this is great, as i said, i found it invaluable in general and in porting CHIP in particular.
WRT -Wno-unused-parameter - i am not aware of a way to disable it for an entire function, unfortunately. a reasonably brief macro, say CHIP_UNUSED, should do the trick and not produce too much clutter. and it if it gets repetitive and most uses don't use most args - maybe it's a sign that API should be reconsidered.
but this is no big deal if it doesn't get adopted. i'm happy that -Wundef will.
thanks again!

bzbarsky-apple added a commit to bzbarsky-apple/connectedhomeip that referenced this issue Oct 5, 2023
bzbarsky-apple added a commit to bzbarsky-apple/connectedhomeip that referenced this issue Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

No branches or pull requests

2 participants