4 ms·
"-Wall -Wextra -Werror" are you allies :)
by wmu 8y ago
"-Wall -Wextra -Werror" are you allies :)
- twodayslate 8y ago-Weverything if using clang
- spc476 8y agoIt's too noisy just by itself. First time I tried it, it complained about padding added to structures. When I packed them, it complained about packed structures.
- MaulingMonkey 8y agoManually pad them, and it'll complain about unused fields ;) I've actually had some pieces of code where it was super useful to enable that padding warning as an error. Some complicated C++ types that needed to have identical memory layouts across compilers yet often weren't because of some really nasty shenanigans... -Weverything is for people who really want to explicitly opt out of every warning they don't like.
- ndesaulniers 8y agoNot recommended. Particularly there are warnings for C++ now that are "mutually unsatisfy-able."
- mort96 8y agoPlease, no, don't use -Werror with -Wall or -Wextra. When you write your code and compile with -Werror on your old version of GCC (either because you're behind on GCC releases, or because you wrote the code in the past), and I want to compile it with my new version which has added some warnings, I don't want to have to mess around in your build configuration and remove -Werror. Instead, do any of the following: * Compile normally without -Werror, but have a test suite which compiles all your tests with -Werror. Make sure to only accept patches which don't break the test suite (probably using some CI system). If you don't want actual tests, a "test suite" which just makes sure `make clean && make CFLAGS=-Werror` doesn't fail would suffice. * Use -Werror for regular builds, but enable only a fixed set of warnings, not -Wall or -Werror. * Make your build system record warnings, and complain about them for every single build, not just the builds which happen to recompile the files which trigger warnings. This doesn't _guarantee_ that your project is warning-free like the other two do, but I imagine a lot of the reason projects end up with warnings is that people just see the warning once, and then never again until the file has to be recompiled. I can't count the number of times I have wanted to use some project, but then had to dig through the project's Makefile or autotools m4/shell soup or gn files or meson files or cmake files or ad-hoc compile script or some other build configuration, just because my compiler is newer than the author's.
- craftyguy 8y ago> Please, no, don't use ... when distributing your code FTFY. It's fine to use them for development, but a major pain in the ass if you are distributing your code for others to compile (looking at you, google).
- mort96 8y agoYeah, I don't care how people or organizations actually write their code, I just want to download the code they distribute (through git or tarballs) and run the commands listed in a readme without the build failing because GCC thinks there's an unnecessary number of parentheses around an expression. The three alternatives were meant as somthing easy one could do instead of blindly using using -Werror to achieve the same advantages, but there are of course more ways to do it. I have also had the fortune of using Goole code. I have been meaning to write a blog post about the issues one encounters when using a Goole library without being a part of Google.
- slavik81 8y agoYou can qualify -Werror so it only applies to missing return statements: -Wall -Wextra -Werror=return-type