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

Always compile tests with all warnings enabled and error out on warnings #1798

Open
t-b opened this issue Oct 16, 2019 · 8 comments · May be fixed by #2245
Open

Always compile tests with all warnings enabled and error out on warnings #1798

t-b opened this issue Oct 16, 2019 · 8 comments · May be fixed by #2245

Comments

@t-b
Copy link
Contributor

@t-b t-b commented Oct 16, 2019

I think we should patch test/CMakeLists.txt to always use -Wall -Werror on *nix and the corresponding MSVC flags. It is way too easy to overlook a warning in the CI output as #1797 has shown.

@nlohmann Thoughts?

@nlohmann
Copy link
Owner

@nlohmann nlohmann commented Oct 17, 2019

I compile the code with maximal warnings when I prepare a release. For CI, such a step would be nice - PRs welcome!

@amiremohamadi
Copy link

@amiremohamadi amiremohamadi commented Oct 19, 2019

@nlohmann
I'll be happy if I can work on it.
I've a question! Should only related flags be added to the test/CMakeLists.txt?

@t-b
Copy link
Contributor Author

@t-b t-b commented Oct 20, 2019

@amiremohamadi I'm not sure what you mean by "related flags" but I would start with -Wall -Werror for gcc/clang and /W4 /WX MSVC. Adding it to test/CmakeLists.txt makes most sense.

@MBalszun
Copy link
Contributor

@MBalszun MBalszun commented Nov 19, 2019

In principle it is a nice goal, but it's always hard to retrofit -Werror / /WX into a project that runs CI on a wide variety of compilers and hasn't used those flags before.

Often you don't have all compilers locally and have to debug through CI cycles and in some cases it is also not clear how to best fix a warning. Particularly problematic: If someone wants to add a new compiler to the CI, is it that person's responsibility to fix all new warnings that that compiler spits out before the PR can be merged?

Maybe a less ambitious first step would be to ensure that the user-visible headers don't produce any warnings (e.g. create a separate test that includes the headers and not much more and compile that single test with -Werror / /WX. From that, iteratively add the flag to more and more tests. In total that is more work, but has the advantage that you can merge intermediate steps and don't get regressions from new pull requests on the way.

@nlohmann
Copy link
Owner

@nlohmann nlohmann commented Nov 19, 2019

I can understand your point, but so far, any warning that did come up eventually lead to an issue here. And if we would be able to detect such a warning in the CI, we have the opportunity to fix it immediately rather than with a delay. That said, I'd rather have such an ambitious step and deal with the problems later than to start every second release notes with notes on fixed warnings which slipped through the release process as, for instance, I do not use MSVC myself. Does this make sense?

@MBalszun
Copy link
Contributor

@MBalszun MBalszun commented Nov 19, 2019

Sure, I haven't actually looked into how many warnings there are currently generated - I just saw that a lot of CI tests started to fail and unless I'm missing something, there is at least one false positive on Appveyor about an unused parameter that is actually used (https://ci.appveyor.com/project/nlohmann/json/builds/28915988/job/jsk75q0pso682j5a).

Luckily, the code base is in good shape and not "that" big, so I guess, fixing all warnings in one PR is manageable.

@stale
Copy link

@stale stale bot commented Dec 19, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@t-b
Copy link
Contributor Author

@t-b t-b commented Sep 2, 2020

@amiremohamadi I've reused some of your commits and co-authored you. The PR is at #2245.

@MBalszun Yes it was quite some work but I do have access to most of the compilers here.

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

Successfully merging a pull request may close this issue.

4 participants
You can’t perform that action at this time.