-
Notifications
You must be signed in to change notification settings - Fork 266
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
Fix warnings #1281
Fix warnings #1281
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is always good to kill warning, but we have generally not worried
about unused parameters. The strncat code properly needs to be converted
to strlcat, which is now our preferred method. For the parameters,
I would prefer using unnamed parameters instead of the (void)param
approach.
I was getting compiler errors about unnamed parameters with that approach (which is what I tried first). |
Interesting. What compiler and what was the error? |
GCC 8.2.1:
|
C99 apparently doesn't allow it: https://stackoverflow.com/questions/8776810/parameter-name-omitted-c-vs-c |
Ugh! |
Can we have a macro for making the unused warning go away? Something like #define NC_UNUSED(A) do{(void) (A);}while(0) with that nobody needs to wonder what the purpose of |
@t-b Sure. What header should I add it to? |
7d6c026
to
520584a
Compare
I think the right place to put that macro would be in include/ncconfigure.h |
This should be used to indicate that a variable is unused in a codeblock.
This could overflow if `tmp` only had a few bytes left in its space given its current contents.
It ends up being `basetime_1 + basetime_2` with a space in between. Make enough room to ensure that it is not truncated.
520584a
to
82d72df
Compare
Updated to add |
@mathstuf I tend to always use the |
Ah, I usually only use it for multi-line expansions or those which otherwise don't allow for a |
Is there any obvious situation where (void)var will not work? |
I can't think of any off-hand. Searching via Github or using Debian Code Search is quite noisy, so I can't point to many other projects doing it. Qt seems to think it sufficient: https://github.com/qt/qtbase/blob/5.12/src/corelib/global/qglobal.h#L117 |
@@ -102,6 +102,11 @@ int nc_create_par(const char *path, int cmode, MPI_Comm comm, | |||
MPI_Info info, int *ncidp) | |||
{ | |||
#ifndef USE_PARALLEL | |||
NC_UNUSED(path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree with this. This clutters up the code only in order to suppress warnings? That's what a warning suppression file is for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These warnings appear from VTK's embedding of NetCDF into its source tree (mainly for Windows users' convenience) where these warnings appear with our default CI configurations. We can certainly keep the patches in our import, but I'm trying to minimize our diffs against upstream code.
As for clutter, I don't see this as "clutter". It's an explicit acknowledgement that path
is not used in the non-parallel path. I wish there were a way to say "warn if this line is no longer necessary", but I don't know of any. This line also fixes the warning for all known compilers with any given set of warning flags. Doing per-compiler suppression regexes or pragmas is, IME, way more complicated.
I can also go back to the literal (void)path;
code rather than adding a new (internal) macro. Would adding a // unused parameter
comment on the lines help?
The usual procedure on projects I've worked on is that the developers build configuration should build without warnings, not that all configurations should build without warnings. I would support fixing any warnings for other configurations which can be fixed without adding complexity to the code base (i.e. lines of code). In many cases this can be accomplished, in others not. Where not, for those who delight (as I do) in warning-free builds, the answer is the warning suppression file. This can be used to turn off specific code warnings that are known to be unimportant, and allow new warnings to pop out as they should. But I don't agree that we should add macros to the code solely to support warning free builds in configurations. That is adding code to support something that's not a requirement. |
For gcc, we have the option to use the -Wno-unused-parameter compiler option |
Maybe I'm missing something, but this sounds like a lot more than one line change per unused parameter. It certainly doesn't sound better according to this metric IMO:
|
@DennisHeimbigner when I say developers build configuration, I mean the one the developers use, i.e. non-paralllel, GNU tools based, on a linux-like system. Right now the C library builds with -Wall with only two warnings. If we would remove those two, we could have a CI job that enforced this warning free build, and that would be great. However, to build without warnings on any arbitrary platform and compiler is too high of a bar. |
I like the I definitely support the build without warnings practice. |
Not sure I follow. If you are referring to the compiler options, then that is a change |
How is |
Yes configure.ac is code but no changes are required to support compiler flags. Simply set them before calling configure, that's how it works. What I have seen done on other projects is to identify a canonical developers build on the CI system, and turn on the compiler option which causes that build to fail if there are warnings. In that way, no one can check in code that contains warnings without failing CI. However, I have not seen at attempt made to make warning-free builds everywhere. I am in support of such efforts which do not cause lines of code to be added. I am not in support if they do. For those who want warning-free builds on other platforms, where that cannot be achieved without needlessly adding to code complexity, I would suggest warning suppression files be used locally to suppress warnings that are annoying. |
Hello, netcdf4/include/ncGroup.h:18:14: error: ‘netCDF::file_id’ defined but not used [-Werror=unused-variable] |
Thanks, I recommend filing a new issue or PR for that. I only fixed the issues I found in the release of netcdf we were using at the time. |
@mathstuf thanks, I've opened a new issue in the C++4 project Unidata/netcdf-cxx4#85 |
These are warnings that show up when building VTK's trimmed down netcdf tree. It is by no means "all" warnings.