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

Modified gcc/clang warning suppression macros to account for some warnings flags being supported by one compiler but not the other #379

Merged
merged 4 commits into from
Sep 16, 2021

Conversation

seanm
Copy link
Contributor

@seanm seanm commented Feb 24, 2021

Added const where possible, then removed casts.

@seanm
Copy link
Contributor Author

seanm commented Feb 24, 2021

@qkoziol I managed to fix a few const warnings... but anything more I think needs someone that knows the codebase well.

@gnuoyd
Copy link
Contributor

gnuoyd commented Feb 25, 2021

It looks like you are changing a public API here, H5Literate2, such that the non-const-ness of the op argument disagrees with the const-ness of the op_data. I think it's too late to change the API, and introducing blatant const disagreement is undesirable.

Maybe some of the const/non-const disagreements that prompted this PR can be avoided in another way? For example, you could create a container for a const pointer, struct t_container { const t *ptr; };, and pass a non-const pointer to the container into the iteration routine. The callback would need to be changed to expect a pointer to struct t_container, of course. There are other ways to solve the problem, this is just one idea that comes to mind.

Thanks for looking at these const-discarding statements, it will be nice to be rid of the warnings (and bugs).

@jhendersonHDF
Copy link
Collaborator

It looks like you are changing a public API here, H5Literate2, such that the non-const-ness of the op argument disagrees with the const-ness of the op_data. I think it's too late to change the API, and introducing blatant const disagreement is undesirable.

Definitely agreed on this point. The op_data pointer is meant to be non-const and there are several tests (currently external to HDF5) that rely on this behavior. For example, consider the case of passing a local variable for op_data that is used to count the number of links that have been iterated over. While it might eliminate the const warnings from HDF5, this would simply push the const warning down to those tests instead.

@qkoziol
Copy link
Contributor

qkoziol commented Feb 26, 2021

@qkoziol I managed to fix a few const warnings... but anything more I think needs someone that knows the codebase well.

The op_data must remain non-const (as @gnuoyd and @jhendersonHDF mention), so the problem is in the caller, not the iterator routines themselves. @gnuoyd's solution of creating a trivial wrapping container is a reasonable way to address it up there.

@seanm
Copy link
Contributor Author

seanm commented Feb 27, 2021

OK, I gave up on solving any of those warnings. Instead, I at least fixed the suppression of a few of them with clang. See new commit.

src/H5public.h Outdated
#define H5_GCC_CLANG_DIAG_OFF(x)
#define H5_GCC_CLANG_DIAG_ON(x)
#endif

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These macros are starting to get ugly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but having hundreds of warnings about trying to suppress non-existent warnings is even uglier IMHO.

@derobins derobins self-assigned this Mar 4, 2021
@derobins
Copy link
Member

derobins commented Mar 4, 2021

Hi Sean,

I've given this some thought, and I don't think that adding things like H5_GCC_CLANG_DIAG_OFF is the way to go. I have a more generic solution in mind that will also work for platforms like Visual Studio. Let's leave this up, though, while I put that together.

@seanm
Copy link
Contributor Author

seanm commented Mar 4, 2021

Fixing the warnings instead of suppressing them is another nice option :)

@seanm
Copy link
Contributor Author

seanm commented Mar 13, 2021

@derobins any word on your alternative? It would be nice to have something, or merge this, because building with clang currently has many warnings about 'unknown pragmas' every time a gcc warning flag that clang doesn't know is disabled with the existing pragmas.

@seanm
Copy link
Contributor Author

seanm commented Aug 12, 2021

@derobins @gnuoyd @qkoziol I've rebased this. Could you review again? It's really annoying getting so many warnings with clang about trying to suppress gcc warnings that clang doesn't support.

@seanm seanm changed the title Fixed a few -Wcast-qual warnings Modified gcc/clang warning suppression macros to account for some warnings flags being supported by one compiler but not the other Aug 12, 2021
H5_GCC_DIAG_ON remains gcc-only.

Added a new H5_CLANG_DIAG_ON that's clang-only, but it's not used anywhere currently.

Added a new H5_GCC_CLANG_DIAG_ON that works with both compilers, which afterall support mostly the same warnings.  Changed almost all uses of H5_GCC_DIAG_ON to use H5_GCC_CLANG_DIAG_ON, with the exception of a couple, where they really were suppressing gcc-only warnings.
Copy link
Contributor

@gnuoyd gnuoyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a step in the right direction.

@seanm
Copy link
Contributor Author

seanm commented Sep 16, 2021

So that's 2 approvals if I'm not mistaken... anything else needed to get this merged?

@lrknox lrknox merged commit 1f2bba5 into HDFGroup:develop Sep 16, 2021
@seanm
Copy link
Contributor Author

seanm commented Sep 16, 2021

Thanks!

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.

6 participants