Feature request: -Wno-unknown-warnings to silently ignore unknown warning control flags.
Motivation/Use case: * Since gcc/g++ intentionally does not have `-Weverything`, there is a number of explicit `-W...` flags one might wish to specify explicitly. Fair enough. * Additional `-W...` flags are introduced in new gcc/g++ versions, which check for new potential code smells, possibly related to later language standards. That's great (thanks!). * Not all platforms run the latest gcc/g++ compiler version. So build tools need to deal with a range of versions. Taking these three points together, we have a problem. The build tool wishes to specify `-Wshiny-new-warning` but may only do so if the gcc/g++ compiler version is above some version X. This is difficult for several reasons: * The documentation does not clearly specify the 1st compiler version that supports each error/warning command line flag. One has to manually backtrack through the release notes for all the compiler versions. In fact the documentation also doesn't make it easy to see which flags are covered by other flags - one has to read through the documentation, one flag at a time, and extract the information from the English text. Some form of a more structured table would have been awesome: 1st compiler version supporting the flag, the list of other flags such as `-Wall` that imply the flag, maybe a list of related flags such as `-f...`. But that aside... * Even if we know which compiler version to check for, this quickly becomes a PITA to maintain in the build tool, given the large number of compiler versions in use in the wild. Having many versions means the compiler has been actively progressing at a fast rate, which is great! But it makes it nasty to deal with providing the correct warning flags for the correct compiler version. This is (mostly) solved with the new proposed flag: the build tool would simply list all the desired warning flags, which would be silently ignored by older compiler versions. Typos are a potential issue. One would have to run a "recent" version without the `-Wno-unknown-warnings` to catch such typos; that would be rare, and is simple enough to do (and automate in the build tool if desired). Another obvious issue is that the new `-Wno-unknown-warnings` flag would only be available starting in a future compiler version. So build tools would have to deal with the problem for a long time before the flag would provide its full benefits. Barring having a working time machine ;-) However, it is much simpler for a build tool to do a single test of whether or not the compiler version supports the proposed new flag, than to deal with the full problem of multiple versions. If the new flag is not supported, the build tool could fall back to using a conservative set of warning flags. Also, as time goes by, older compiler versions would eventually be phased out, so even this test would be (eventually) removed. Sure, it would take a decade or more, but: as the saying goes, "The best time to plant a tree is 20 years ago; the second best time is today". Thanks, Oren Ben-Kiki
Re: Feature request: -Wno-unknown-warnings to silently ignore unknown warning control flags.
On Thu, Oct 12, 2017 at 1:14 PM, Jonathan Wakely> * Additional `-W...` flags are introduced in new gcc/g++ versions, which > > check for new potential code smells, possibly related to later language > > standards. That's great (thanks!). > > And the most widely useful ones are added to -Wall so you don't need > to know about them and add them explicitly. > "Most" != "All". IMVHO it is too strong to say "you don't need to know about [other ones]". You might say you don't _typically_ need to know about them. Quite possibly so; but the feature request is for the use case of people who, like me, find some of the non-Wall non-Wextra warnings to be useful. These additional flags exist for a reason...
Re: Feature request: -Wno-unknown-warnings to silently ignore unknown warning control flags.
On Thu, Oct 12, 2017 at 9:40 PM, Andrew Pinski > -Wno-unkown-warning has already been handled silently since 4.6.0 > (which was released March 25, 2011): > https://gcc.gnu.org/onlinedocs/gcc-4.6.0/gcc/Warning-Options.html > > When an unrecognized warning option is requested (e.g., > -Wunknown-warning), GCC emits a diagnostic stating that the option is > not recognized. However, if the -Wno- form is used, the behavior is > slightly different: no diagnostic is produced for -Wno-unknown-warning > unless other diagnostics are being produced. This allows the use of > new -Wno- options with old compilers, but if something goes wrong, the > compiler warns that an unrecognized option is present. > True, writing -Wno-some-future-version-warning-option is silently ignored. But -Wsome-future-version-warning-option currently generates a diagnostic message. The proposal is to have an explicit `-Wno-unknown-warnings` flag to suppress this diagnostic message. The documentation uses `-Wno-unknown-warning` as an example name (instead of saying something unwieldy like `-Wno-some-future-version-warning-option`). There's no actual `-Wno-unknown-warning` option. Here is a concrete example to make this less abstract: Suppose one wants to use `-Wsuggest-final-methods`. That's nice but versions 4.* of g++ do not support this flag; the build tool needs to avoid specifying this command line option if a 4.* g++ version is used. The problem isn't specifically about this flag and version; this is just an example; there are plenty of new useful warnings added in the recent past, such as (partial list): `-Wnonnull-compare`, `-Wnull-dereference`, `-Walloc-zero`, `-Wduplicated-cond`, `-Wrestrict`, ... Thanks, Oren.
Re: Feature request: -Wno-unknown-warnings to silently ignore unknown warning control flags.
On Thu, Oct 12, 2017 at 10:10 PM, Jonathan Wakely wrote: > > "Most" != "All". > > > > IMVHO it is too strong to say "you don't need to know about [other > ones]". > > I didn't say that. I said you don't need to know about the -Wall ones, > because you get them anyway. > Ah, sorry, I misunderstood. Yes, one doesn't need to worry about the ones covered by `-Wall` (or `-Wextra` for that matter). > > You might say you don't _typically_ need to know about [the other > ones]... > > Yes, I'm not disputing that, just saying that it's not a critical > issue, because it only applies to some of the less commonly-needed > warnings. > I agree this isn't a critical issue. This is a feature request; if it was a critical issue I would have tried hard to pose it as a bug report ;-) IMVHO, even though it isn't a critical issue, it makes sense as a proposed feature. > I note that you didn't quote or respond to the part where I said > anybody could add the docs you want, but that nobody ever does it :-) > Yes, sorry. It is a fair point. That said, fixing the documentation is a separate issue than the proposed new `-Wno-unknown-warnings` flag. In fact, having such a flag would make fixing the documentation less of an issue. I also _suspect_ adding this new flag would also be *much* less work - intuitively it should be a very localized change to the code. But I have no familiarity with the g++/gcc internals, so I could be wildly wrong assuming that.
Re: Feature request: -Wno-unknown-warnings to silently ignore unknown warning control flags.
On Fri, Oct 13, 2017 at 4:47 AM, Martin Sebor wrote: > My organization was particularly focused on warnings so I'm quite > familiar with the challenges you're hoping to overcome. I figured I wasn't the only one :-) But it is good to hear from others. > My > best advice is to either write a script to determine the options > the target compiler supports and use only those, or write > a compiler driver that handles this for you (it doesn't relieve > you of the tedious task of researching all the options and hard > wiring them into the driver(*)). Yes, this is probably the best one can do right now. > This isn't to say that GCC shouldn't make it easier, but as > you note, even if and when it does, it will take years before > the solution is universally available. > Making the world a better place for the next generation is a worthy goal ;-) > [*] We wrote a script scrape those off the online HTML manual > and create a "database" mapping options to GCC versions they > were introduced in (or first documented in, as not every option > always gets documented as it gets added). > Sounds interesting! I don't suppose this driver is available as a separate standalone tool? Thanks, Oren.
Re: Feature request: -Wno-unknown-warnings to silently ignore unknown warning control flags.
On Fri, Oct 13, 2017 at 10:04 PM, Eric Gallager wrote: > If you use autoconf to generate a configure script for your project, I > recommend using the macros from gnulib's manywarnings.m4 and related > files: > > https://www.gnu.org/software/gnulib/manual/html_node/ > warnings.html#warnings > https://www.gnu.org/software/gnulib/manual/html_node/ > manywarnings.html#manywarnings > Thanks for the pointers. I'm not currently using auto tools, but I might end up having to use them, or cmake. Having these macros would help. I still wish we had `-Wno-unknown-warnings` though - it would make life much simpler. Thanks, Oren.