exercism / cpp

Exercism exercises in C++.
https://exercism.org/tracks/cpp
MIT License
257 stars 211 forks source link

Warning Levels for Visual Studio's C++ compiler #302

Open KevinWMatthews opened 5 years ago

KevinWMatthews commented 5 years ago

Copying an issue raised on exercism/exercism for better visibility:

In the C++ track, exercises come with a CMakeLists.txt file that configures CMake for each exercise, and I noticed that when building C++ solutions to exercises certain warnings I'd expect to see aren't appearing.

It looks like warning levels are set to be verbose for Clang and GNU compilers but there's no setting that addresses the default compiler MSVS ships with.

https://stackoverflow.com/questions/2368811/how-toset-warning-level-in-cmake/50882216#50882216

This SO answer describes how that could be addressed for visual studio, and it would be a great help to new programmers such as myself if this configuration option could be added.

KevinWMatthews commented 5 years ago

Docs on MSVC compiler warnings.

At first glance it looks like we'll want /W4 and /WX and possibly /Wall.

/Wall turns on compiler warnings that are off by default. They state that:

The C runtime libraries and the C++ standard libraries are intended to emit no warnings only at warning level /W4

Do we want this? I don't have a Windows box to test on.

Warnings in stdlib wouldn't affect our projects if we only link against it, right?

Nolshine commented 5 years ago

An error warning level of higher than /W4 in Visual C++ tends to bury the user in warnings generated by the standard library.

https://stackoverflow.com/questions/4001736/whats-up-with-the-thousands-of-warnings-in-standard-headers-in-msvc-wall

For most users and especially newer C++ programmers, /W4 seems optimal, because most users don't need to see those warnings.

KevinWMatthews commented 5 years ago

@Nolshine Thanks for the info!

We'll stick with /W4. Adding /Wall and promoting warnings to errors using /WX would mean that students would never be able to compile - not good.

arcuru commented 5 years ago

I have no clue about the warning levels in MSVC to be honest, so whatever suggestion here is probably fine.

I can test this on a Windows box at some point.

arcuru commented 5 years ago

@KevinWMatthews The Github Actions are now running on this repo, and they run all the tests on Windows and spit out all the output, so you should* be able to test that here. Here is the Windows run: https://github.com/exercism/cpp/runs/222211460

They should run on a PR opened against the master branch, as well as pushes to master, so you should be able to test in a PR.