gcc中的 -w -W和-Wall选项

-w 的意思是关闭编译时的警告

就是说编译后不会显示任何warning.

- Wall 启用大部分警告

同时也会启用以下警告标志

 -Waddress 
 -Warray-bounds=1 (only with -O2) 
 -Wbool-compare 
 -Wbool-operation 
 -Wc++11-compat  
 -Wc++14-compat 
 -Wcatch-value (C++ and Objective-C++ only) 
 -Wchar-subscripts 
 -Wcomment 
 -Wduplicate-decl-specifier (C and Objective-C only) 
 -Wenum-compare (in C/ObjC; this is on by default in C++) 
 -Wformat 
 -Wint-in-bool-context 
 -Wimplicit (C and Objective-C only) 
 -Wimplicit-int (C and Objective-C only)
 -Wimplicit-function-declaration (C and Objective-C only) 
 -Winit-self (only for C++) 
 -Wlogical-not-parentheses 
 -Wmain (only for C/ObjC and unless -ffreestanding) 
 -Wmaybe-uninitialized 
 -Wmemset-elt-size   
 -Wmemset-transposed-args 
 -Wmisleading-indentation (only for C/C++) 
 -Wmissing-attributes 
 -Wmissing-braces (only for C/ObjC) 
 -Wmultistatement-macros 
 -Wnarrowing (only for C++) 
 -Wnonnull 
 -Wnonnull-compare      
 -Wopenmp-simd 
 -Wparentheses 
 -Wpointer-sign 
 -Wreorder 
 -Wrestrict 
 -Wreturn-type 
 -Wsequence-point 
 -Wsign-compare (only in C++) 
 -Wsizeof-pointer-div 
 -Wsizeof-pointer-memaccess 
 -Wstrict-aliasing 
 -Wstrict-overflow=1  
 -Wstringop-truncation 
 -Wswitch 
 -Wtautological-compare 
 -Wtrigraphs 
 -Wuninitialized 
 -Wunknown-pragmas 
 -Wunused-function 
 -Wunused-label 
 -Wunused-value 
 -Wunused-variable 
 -Wvolatile-register-var

要注意的是, -Wall 并不含有所有的警告标志。不包含的警告通常不需要注意,但并不代表不会出问题。

-W 标志,现在被 -Wextra 所代替

他将会启用 -Wall 选项没有启用的警告标志,其中包括

 -Wclobbered 
 -Wcast-function-type 
 -Wempty-body 
 -Wignored-qualifiers 
 -Wimplicit-fallthrough=3 
 -Wmissing-field-initializers 
 -Wmissing-parameter-type (C only) 
 -Wold-style-declaration (C only) 
 -Woverride-init     
 -Wsign-compare (C only) 
 -Wtype-limits 
 -Wuninitialized 
 -Wshift-negative-value (in C++03 and in C99 and newer) 
 -Wunused-parameter (only with -Wunused or -Wall) 
 -Wunused-but-set-parameter (only with -Wunused or -Wall)

选项-Wextra选项还会在以下情况下显示警告消息:

  • 指针与带有“ <”,“ <=”,“>”或“> =”的整数零进行比较。
  • (仅C ++)枚举数和非枚举数都出现在条件表达式中。
  • (仅C ++)模糊的虚拟基础。
  • (仅C ++)对已声明为“寄存器”的数组进行下标。
  • (仅C ++)采用已声明为“寄存器”的变量的地址。
  • (仅C ++)未在派生类的副本构造函数中初始化基类。
qrcode

创建时间:2020-04-13 08:20:06

最后修改:2020-06-13 10:40:33