Live data from Hacker News

Don't use -Werror

blog.schmorp.de

21–30 of 74 posts

Re: Don't use -Werror

#21

Go 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?"

Go has something of an imposed rigidity that a lot of C programmers I think wouldn't tolerate well (culturally, viscerally),- one example: the whole comment out all unused variables because you commented out a function for debugging purposes during development (couldn't just pass a flag to the compiler, at least last time I used Go). Aside - I seem to remember a Blog post you wrote on your experience with the Go lang…

Commenting out code correctly, in a way that avoids complaints about unused code, should be possible to do in a proper IDE.

Re: Don't use -Werror

#22
post #2

Summary: 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.

It'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.

Re: Don't use -Werror

#24
Why 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?

Re: Don't use -Werror

#25
post #9

I 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 ther…

-Wno-specific-warning (I think it's always had this, or at least for a very long time).

And:

  #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.

Re: Don't use -Werror

#26
post #24

Why 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?

In 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.

Re: Don't use -Werror

#27
post #9

Earlier quoted context omitted.

-Wno-specific-warning (I think it's always had this, or at least for a very long time).

And: #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…

clang understands #pragma GCC diagnostic fine, no need to have special code for it.

Re: Don't use -Werror

#28
post #21

Earlier quoted context omitted.

Go has something of an imposed rigidity that a lot of C programmers I think wouldn't tolerate well (culturally, viscerally),- one example: the whole comment out all unused variables because you commented out a function for debugging purposes during development (couldn't just pass a flag to the compiler, at least last time I used Go). Aside - I seem to remember a Blog post you wrote on your experience with the Go lang…

Commenting out code correctly, in a way that avoids complaints about unused code, should be possible to do in a proper IDE.

Go mentality says that you shouldn't need an IDE for coding in a language.

Re: Don't use -Werror

#29
post #24

Why 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?

> Why can't developers, y'know, ACTUALLY READ THE BLOODY WARNINGS?

Same reason checklists are handy: People automatically optimize away "dead code" (nevermind the fact that reading the warnings is sometimes useful.)

> And then, y'know, they could FIX MORE THAN THE FIRST ONE after a single build pass?

I do get multiple errors with -Werror and kin, FWIW. But again we run into human nature - C++ errors get unreliable after the first one, so people tend to optimize away the "useless" step of reading the second error...

Re: Don't use -Werror

#30
post #2

Summary: 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.

Better if the third parties hit you up with the bug report and you come back with a patch.
Post reply on HN