1

clang, but NOT gcc, has a -Weverything option which appears to include things such as -Wpedantic. You can test it here: https://godbolt.org/z/qcYKd1. See the top-right of the window for where I have typed in -Weverything as an explicit compiler option.

Notice the -Wvla-extension warning we get since we are relying on a C99 extension in C++ in this case, and we have -Weverything set. We get the same warning if we just use -Wpedantic, as shown here: https://godbolt.org/z/M9ahE4, indicating that -Weverything does in fact include -Wpedantic.

We get no warning if we have neither of those flags set: https://godbolt.org/z/j8sfsY.

Despite -Weverything existing and working in clang, however, I can find no documentation whatsoever on its existence, neither in the clang man pages nor in the online manual here: https://clang.llvm.org/docs/DiagnosticsReference.html. Maybe I'm looking in the wrong place? I'm not super familiar with clang's manual.

So, what does -Weverything include and where is it documented?

It seems logical to do something like -Wall -Werror -Weverything, but I don't know how that differs from just -Wall -Werror.

Gabriel Staples
  • 36,492
  • 15
  • 194
  • 265

1 Answers1

4

Dope! I just found it.

The bottom of the main clang documentation index page: https://clang.llvm.org/docs/index.html, under the "Indices and tables" section at the very bottom, has a "Search Page" link. Using that link, here is my search for "-Weverything": https://clang.llvm.org/docs/search.html?q=-Weverything, which brings me to the official documentation here!: https://clang.llvm.org/docs/UsersManual.html?highlight=weverything#cmdoption-weverything. Done! There it is!

enter image description here

See also: https://clang.llvm.org/docs/UsersManual.html?highlight=weverything#diagnostics-enable-everything

enter image description here

And the parts I really care about (emphasis added):

Since -Weverything enables every diagnostic, we generally don’t recommend using it. -Wall -Wextra are a better choice for most projects. Using -Weverything means that updating your compiler is more difficult because you’re exposed to experimental diagnostics which might be of lower quality than the default ones. If you do use -Weverything then we advise that you address all new compiler diagnostics as they get added to Clang, either by fixing everything they find or explicitly disabling that diagnostic with its corresponding Wno- option.

So, my final recommendation is to use -Wall -Wextra for warnings, but NOT -Weverything, and personally, not -Wpedantic (or -pedantic--same thing) either since I frequently rely on gcc compiler extensions for low-level embedded work and hardware-centric programming, especially on microcontrollers.

I also strongly recommend forcing all warnings into errors with -Werror. This is particularly important for safety-critical code and/or embedded firmware that needs to run forever, because it forces you to fix all warnings to get the code to fully compile. So, my final recommendation is this, as I describe further in my github repo below:

# Apply "all" and "extra" warnings, and convert them all to errors
# to force you to actually abide by them!
-Wall -Wextra -Werror  

You can read my more-thorough opinion and research on this topic in my GitHub repo here: https://github.com/ElectricRCAircraftGuy/eRCaGuy_hello_world#build-notes.

Extra notes: -Wpedantic == -pedantic:

In gcc, they are the same:

-Wpedantic
-pedantic

Issue all the warnings demanded by strict ISO C and ISO C++...

In clang, they appear to be the same too, in testing and documentation. Clang also strives to be gcc-compatible in their syntax and usage: "End-User Features:"..."GCC compatibility".

Related:

  1. Why should I always enable compiler warnings?
Gabriel Staples
  • 36,492
  • 15
  • 194
  • 265
  • @JaMiT, regarding your first comment, they are the same. Both gcc and clang treat `-pedantic` and `-Wpedantic` the same as far as I can tell. See the gcc documentation, for instance: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html. One is an alias of the other. They are listed together. Regarding the 2nd comment, I didn't make it clear I knew what I was talking about. My usage of `-Werror` is intentional--to force all warnings into errors, and I recognize it has nothing to do with warnings otherwise and does not contain any warnings. I'll update the answer a bit to make that clear. – Gabriel Staples Oct 01 '20 at 04:33
  • Answer updated. Note: the only reason I mention `-Werror` is to solidify my best practices for myself and others. This answer is kind of the culmination of years of programming: finally settling on an opinion based on research, experience, and, this answer as the final piece I suppose. I just got all thrown off by clang vs gcc though, and it (clang's extra `-Weverything` option here) through a wrench in my understanding until I found this documentation. – Gabriel Staples Oct 01 '20 at 04:41
  • through --> threw – Gabriel Staples Oct 01 '20 at 04:53
  • OK, I do not recall seeing `-Wpedantic` in use, but apparently it is appropriate. Now my objection is that you put ***WAY** too much emphasis* on proving that the two options are equivalent. It's garish and really detracts from your presentation. Since you wanted to make a change to address my (now retracted) comment, all that was needed was something like changing "*not* `-Wpedantic` either" to "*not* `-Wpedantic` (or `-pedantic`) either" to acknowledge that both options exist. – JaMiT Oct 01 '20 at 23:16
  • I had to look up the meaning of "garish". I don't mean to sound that way. I'm just doing what I do: I research answers and write down the results. I think it's useful information and doesn't detract from the main points. Even if for no other purpose than to remind myself in the future of those details and where the documentation is found, I'd leave it. But, I think others will find those extra details useful and not garish. – Gabriel Staples Oct 02 '20 at 02:18
  • You might have misunderstood the meaning you looked up. The problem is not the usefulness of the information, but the presentation. Oh, and it's not "details" that are garish, but "detail" (singular), as in both `-Wpedantic` and `-pedantic` are valid options. This one section (not your entire answer) is garish because you devoted an entire section to a detail that is worth mentioning, but barely so. It's like you're not satisfied correcting me in the comments and want to make sure no one in the future would ever dream of questioning you again. Overreaction. – JaMiT Oct 02 '20 at 02:44
  • Note: The only reason I believe the detail is worth mentioning at all is that your image lists `-pedantic` while your text uses `-Wpedantic`. Inconsistencies are worth acknowledging so that readers know it is not a typo. (You have now acknowledged it in your question. This is not a suggestion for something to do, but a rationale for why I called this detail "worth mentioning, but barely so".) – JaMiT Oct 02 '20 at 02:49