What warnings are included in Clang's -Wall and -Wextra?

隐身守侯 提交于 2019-11-30 00:31:53

问题


I've found Clang's documentation to be quite poor. I haven't been able to find much of a list of available Clang warning flags. I'm interested particularly in C/C++ warnings, but this is a bit of a general issue.

GCC lists and describes warnings here, and also lists what is included in -Wall and -Wextra: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#Warning-Options

What warning flags are included with Clang's -Wall and -Wextra?

I can scour the Clang release notes for each version to see what new warning flags are introduced each time (e.g. http://llvm.org/releases/3.4/tools/clang/docs/ReleaseNotes.html), but is there an easier list and/or description of Clang's warnings? This would be extremely useful. I need to know what is included in -Wall and what is not, so I can consider turning on those that are not.

(I know that -Weverything exists for Clang - might I have to resort to using that and just explicitly disabling the ones I don't like? More documentation would make this much more ideal.)


回答1:


You can check the source code:

For example,

def : DiagGroup<"all", [Most, Parentheses, Switch]>;

// Warnings enabled by -pedantic.  This is magically filled in by TableGen.
def Pedantic : DiagGroup<"pedantic">;

// Aliases.
def : DiagGroup<"", [Extra]>;                   // -W = -Wextra

For -Wall look at the Most, Parentheses, Switch. You can find:

def Most : DiagGroup<"most", [ 
....

further down the file. Similarly, for extra:

def Extra : DiagGroup<"extra", [
    MissingFieldInitializers,
    IgnoredQualifiers,
    InitializerOverrides,
    SemiBeforeMethodBody,
    MissingMethodReturnType,
    SignCompare,
    UnusedParameter
  ]>;



回答2:


Clang used to be very bad at documenting what was available. Though from release 4.0.0 on, they have fixed it. For older releases one can try or consult the source code. At the compiler-warnings page on Github you can find an extract of the warnings based upon the source code.

So you can find the documentation over the latest flags at the documentation pages, as well as the matching documentation for a specific release at their release pages (4.0.0).

Clang-cl has its own warning flags, of which the mapping can be found on its documentation



来源:https://stackoverflow.com/questions/24904101/what-warnings-are-included-in-clangs-wall-and-wextra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!