6 ms·
Don't use -Werror
- ars 10y agoSummary: Enable -Werror in debug builds, disable it in production builds (in publicly released builds). Reason: -Werror is helpful for you, useless for a 3rd party.
- arcticbull 10y agoCame here to say exactly this. No reason you can't be extra careful during development and turn the flags off in release configuration.
- careersuicide 10y agoI agree whole heartedly. When I'm programming I typically want most things that would cause a warning to stop me in my tracks. However I cannot count the number of times I've been trying to build someone else's code and the configuration uses -Werror and things that didn't raise a warning on their version of gcc or clang do on mine and now I've got to fix possibly dozens of not actual errors.
- pixelbeat 10y agoYes exactly. For example GNU coreutils auto enables -Werror for devs when running from a git repo, whereas tarball releases do not add that option. See: http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=blob;f=configure.ac;hb=v8.25#l102 http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=blob;f=confi...
- astrange 10y agoIt's not scalable for you either. If everything becomes an error, you can't go a single day without fixing it and everything the compiler + your dependencies - aka, just some other people you've never met - complains about. In particular if you update a library and they deprecate some functions, -Wdeprecated will start emitting some warnings, which are now errors. Do you think you can fix that in a day? It could take months to fix something that's literally not a problem yet. By the way, I couldn't build MariaDB on this one machine because some plugin we don't use has -Werror set and fails with obscure C++ nonsense.
- 2trill2spill 10y ago> In particular if you update a library and they deprecate some functions, -Wdeprecated will start emitting some warnings, which are now errors. Do you think you can fix that in a day? It could take months to fix something that's literally not a problem yet. It doesn't take months to add -Wno-deprecated to a Makefile.
- powercf 10y ago> It doesn't take months to add -Wno-deprecated to a Makefile. After which you no longer have any visibility on what deprecated fxns you're calling, which means one day updating that library again is going to completely block you until you rework your interface. -Wno-error=deprecated would probably be better.
- MaulingMonkey 10y agoEven better in my experience: A work item to be triaged, generated when you add either.
- Sir_Cmpwn 10y agoBetter if the third parties hit you up with the bug report and you come back with a patch.
- ridiculous_fish 10y agoGo has the equivalent of -Werror on all the time. How does it address the issue of "your compiler might emit a warning that my compiler didn't?"
- hiimnate 10y agoThere's only 2 go compilers, there's like 20 c compilers
- MichaelMoser123 10y agoeven slightly different versions of gcc do emit very different warnings. its not very predictable.
- deleted 10y ago[deleted]
- jcbeard 10y agoHave you ever used multiple compilers? Try compiling the same thing written in C or C++ with: clang, then gcc, then icc and see how -Werror treats you within any remotely interesting code. It's hard to predict what one compiler feels is perfectly okay (or perhaps ambiguous) and another feels is downright wrong. It's downright infuriating in a cross-architecture environment. -Wall -Wpedantic and -Wextra are usually plenty.
- MaulingMonkey 10y ago> It's downright infuriating in a cross-architecture environment The only thing more infuriating than being unable to predict when your code is going to fail the build because of -Werror on some other compiler/arch, is your bugs generating warnings on some compiler/arch es that don't fail the build. Cross-architecture environments are one of the main reasons I want to enable -Werror and kin. I won't notice all the warnings otherwise.
- Manishearth 10y agoThere are only 2 go compilers, with very few warnings. C has a whole bunch of compilers and some of them have a whole bunch of warnings.
- deleted 10y ago[deleted]
- raverbashing 10y agoI see the issue as: there are warnings and warnings One thing is for the compiler to warn about something like implicit conversion of one type to another. Another, very different, if warning for things that are correct but might be in error (like 'for' without brackets, etc)
- Retric 10y agoNon idiomatic code is an error. Not because computers have an issue, but because it wastes fractions of a second every time someone reads the code. PS: It's the same reason you capitalize the first letter in a sentence.
- raverbashing 10y ago1 - That's the job of a linter 2 - automatically generated code has no obligation to be idiomatic 3 - If I had a cent for every time "idiomatic" code got in the way of readability I'd be a millionaire right now
- Retric 10y agoIf writing idiomatic code is causing readability problems your doing it wrong. Successful code is read far more than it's written and even machine generated code needs to be well written to locate bugs etc. iF YoR CodE LoOks lIKe tHIs, yOu FaIl.
- raverbashing 10y ago> If writing idiomatic code is causing readability problems your doing it wrong. Sure, because breaking a 82 char line in python in 2 lines (because pep8) is much more readable than leaving it at 82 chars.
- Retric 10y agoA 65+ character line is already ugly. 80 is an arbitrary but sensible cutoff.
- CamperBob2 10y agoI use -W4 and -WX with MSVC to enable the highest warning level and flag all warnings as errors. Then I disable a couple of the more pointless warnings (unreferenced formal parameter, unreferenced local function, unreachable code...) that would otherwise keep me from being able to use -W4 without jumping through arbitrary hoops. The problem with GCC, at least at the time I was using it several years ago, is that there seemed to be no way to disable individual warnings. Is that still true (or was it ever?)
- tubs 10y ago-Wno-specific-warning (I think it's always had this, or at least for a very long time).
- MaulingMonkey 10y agoAnd: #pragma GCC diagnostic push #pragma GCC diagnostic warning "-Wspecific-warning" #pragma GCC diagnostic ignored "-Wspecific-warning" ... #pragma GCC diagnostic pop For warnings you want to disable in a smaller scope. s/GCC/clang/ for clang. Bonus points: #define MM_WARNING_IGNORE_GCC(x) MM_IF_GCC( _Pragma(GCC diagnostic ignored x) ) #define MM_WARNING_IGNORE_CLANG(x) MM_IF_CLANG( _Pragma(clang diagnostic ignored x) ) #define MM_WARNING_IGNORE_MSVC(x) MM_IF_MSVC( __pragma(warning(disable: x)) ) #define MM_WARNING_PUSH() \ IF_GCC( _Pragma(GCC diagnostic push) ) \ IF_CLANG( _Pragma(clang diagnostic push) ) \ IF_MSVC( __pragma(warning(push)) ) #define MM_WARNING_POP() \ IF_GCC( _Pragma(GCC diagnostic pop) ) \ IF_CLANG( _Pragma(clang diagnostic pop) ) \ IF_MSVC( __pragma(warning(pop)) ) MM_WARNING_PUSH() MM_WARNING_IGNORE_GCC("-Wspecific-warning") MM_WARNING_IGNORE_CLANG("-Wspecific-warning") MM_WARNING_IGNORE_MSVC(1234) ... MM_WARNING_POP() Defining MM_IF_*() is left as an exercise to the reader.
- bla2 10y agoclang understands #pragma GCC diagnostic fine, no need to have special code for it.
- gerdesj 10y agoSo, clever bloke declares error checking is wrong or something. As a non serious programmer it would seem to me that -Werror is either not granular enough or simply not fit for purpose. I wonder if -Werror is defined in a standard somewhere and hence has a clearly defined meaning.
- MaulingMonkey 10y ago> Enabling -Werror in distributions virtually guarantees that they won't build: Even if you took care of all compiler warnings in all compilers for which you enable this switch, it's just a question of time till a new compiler version comes along that has a new warning message and - BOOM. This is a feature. This triggers a review of the new warnings introduced by the new compiler version, to see if they have found bugs, or should be squelched per false positive, or should be squelched project-wide. > Two recent examples are squid and qemu-linaro, two packages I had to compile from source as Debian GNU/Linux didn't have (good enough, or any) packages for them. The fundamental problem here is using a contributor's build environment (where I want -Werror to get them to contribute warning-induced bugfixes, or squelches/ignores if they're really false positives) for a non-contributor's task (where they just want the final binary, and aren't going to bother reporting the warnings even if I want them.) Non-contributors building from source isn't a relevant niche to me (I generally ship binaries), but I can sympathize with the request for a warnings-as-warnings fast build path for them. But make -Werror the default build path, for developers. This needs to be opt-out, not opt-in.
- andrewchambers 10y ago> This is a feature. This triggers a review of the new warnings introduced by the new compiler version, to see if they have found bugs, or should be squelched per false positive, or should be squelched project-wide. The thing is, the software already had these bugs, and worked well enough for most people despite them, its not worth breaking the build over unless you are the developer.
- brian-armstrong 10y agoThose bugs could be buffer overruns or similar security problems. Just because the program appears to work doesn't mean it should be used.
- andrewchambers 10y agoThey could be, or they could be nothing, and the program might not even be exposed to untrusted input anyway. We can have a discussion about perhaps splitting programs into security classes, though I would prefer the upstream people use the cutting edge security analysis, then backport patches with security advisories.
- KKKKkkkk1 10y agoIf we agree that compilers can only detect trivial issues (cf. Rice's theorem), then arguing about -Werror is masturbation. Sorry.
- jsizz 10y agoWhy can't developers, y'know, ACTUALLY READ THE BLOODY WARNINGS? And then, y'know, they could FIX MORE THAN THE FIRST ONE after a single build pass?
- ezyang 10y agoIn my observation, the problem is recompilation avoidance. If you miss it the first time around (maybe you're just trying to get the thing to run) they won't come back unless you do a full rebuild. With a little care you can build a build system that will print them out every time you run, but it takes some care.
- jsizz 10y agoWhy avoid recompiling? Why this reluctance to do a full rebuild? I started programming in a world where you had to wait a day to get 300 lines of Fortran built. Now I routinely build the whole 44Gb of community ports of a major Linux distro in three days on a three hundred buck box at home. There are 24 hours in a day, and your full rebuild will go just fine while you sleep, so long as you DON'T use -Werror.
- MaulingMonkey 10y agoI don't want to eat a 24h overnight full rebuild every time I fix a single typo. I do want to verify it still builds (i.e. I haven't missed one of the use cases of a renamed variable.) The shorter the feedback loop, the less context I have to rebuild for errors, the faster I can fix the error, the more efficient I am. I'm not so far along that I make much use of the red squiggly lines generated by my IDE to highlight syntax errors before I even hit save - I use too many languages that can't be adequately parsed that fast for them to be terribly accurate - but it's a sign of just how much people want to shorten that feedback loop. Have the CI server do full rebuilds overnight? Sure. Although I still have to bug my coworkers to pay enough attention to the CI server to even notice it's gone red from their changes, at times. Convincing them to read through the warning logs is a nonstarter.
- mkj 10y ago
- andrewchambers 10y agoI always argued compiling/looking for errors are two different things and should be two different tools. Developers need linters/warnings. Packagers don't need this information unless it will stop the software from functioning as it has previously been functioning (prexisting bugs included).
- malkia 10y agoIn general don't listen to "Don't use, or use only ...." advice, there is often the case for when you may need it, no need to get religious over it.
- viraptor 10y agoFor fun case of "I get an error but you don't", here's a bug: https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/305176 https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/... - around 5 years of GCC versions which ignore the explicit `(void) write(...)` and still report an error.
- 2trill2spill 10y ago> There is a common complaint about my software - some compilers sometimes emit warnings when compiling some code, which some people sometimes find somewhat offensive. They can be very useful though, which is why I investigate the ones I know of. If you don't take care of every warning you may miss a new warning amongst all the old warnings. That's why -Werror is nice, it forces you to deal with every warning as they pop up. Also when I compile someone else's software and there is a bunch of warnings popping up it makes me question the quality of the codebase. The code quality may be fine but it doesn't look good to the outside world. > Even if you took care of all compiler warnings in all compilers for which you enable this switch, it's just a question of time till a new compiler version comes along that has a new warning message and - BOOM. Great if a new warning pops up with a different compiler I want to know about that. It's either a bug in my code or a false positive. Using -Werror is more work but it improves code quality.
- kahrkunne 10y agoTo generalize: Don't put debugging shit in production code.
- davidron 10y agoThis article is basically a corollary of the Robustness Principal, "Be conservative in what you do, be liberal in what you accept from others". In this case we're accepting certain dependencies from others and we SHOULD be liberal/tolerant of dependencies that work but generate warnings.
- jschwartzi 10y agoThere are some legitimate reasons for leaving -Werror enabled all the time. In the embedded world, for example, I'm less interested in supporting a wide variety of compilers, and more interested in rigidly complying with my particular toolchain's definition of "correct." In that case, I'm going to ask it to be as pedantic as possible because I'm never going to compile the code with any other toolchain, and I'd like to minimise the possibility of a bug because the code is going somewhere that a human won't be able to follow.