gcc-4.8.1中O2优化级别的推荐警告标志

时间:2014-02-06 13:55:58

标签: c++ c gcc gcc-warning

我最近从gcc-4.2.4转到gcc-4.8.1。 gcc-4.8.1中O2优化级别推荐的gcc警告选项是什么?

我一直在gcc-4.2.4中使用以下警告标志: -Wall -Wno-parentheses -Wpointer-arith -Wcast-align -Wsign-compare -Wnon-virtual-dtor -Wnon-template-friend -Woverloaded-virtual -Wsign-promo

2 个答案:

答案 0 :(得分:3)

我宣传的惯例是:

-Wall -Wextra -pedantic

访问GCC文档,了解有关哪些特定标志的详细信息。

答案 1 :(得分:2)

取决于您要构建的目标。 对于ubuntu,我会这样做:

CWARN   =-Wall -Wextra -Wattributes -Wbuiltin-macro-redefined -Wcast-align -Wconversion -Wdeclaration-after-statement    \
         -Wdiv-by-zero -Wdouble-promotion -Wenum-compare -Wfloat-equal -Wimplicit-int -Winit-self -Wint-to-pointer-cast  \
         -Wjump-misses-init -Wlogical-op -Wmissing-braces -Wmissing-field-initializers -Wmissing-parameter-type          \
         -Woverflow -Wpointer-arith -Wpointer-sign -Wpointer-to-int-cast -Wredundant-decls -Wreturn-type -Wshadow        \
         -Wsign-compare -Wtype-limits -Wuninitialized -Wwrite-strings \
         -Wno-unused-parameter -Wno-multichar -Wno-strict-aliasing
CXXWARN =-Wall -Wextra -Wattributes -Wbuiltin-macro-redefined -Wc++0x-compat -Wcast-align -Wconversion -Wdiv-by-zero     \
         -Wdouble-promotion -Wenum-compare -Wfloat-equal -Winit-self -Wint-to-pointer-cast -Wlogical-op -Wmissing-braces \
         -Wmissing-field-initializers -Woverflow -Wpointer-arith -Wredundant-decls -Wreturn-type -Wshadow -Wsign-compare \
         -Wsign-promo -Wtype-limits -Wuninitialized -Wwrite-strings \
         -Wno-unused-parameter -Wno-multichar -Wno-strict-aliasing

对于独立内核开发,我这样做:

CWARN    =-Wall -Wextra -Wattributes -Wbuiltin-macro-redefined -Wcast-align -Wconversion         \\
          -Wdiv-by-zero -Wdouble-promotion -Wenum-compare -Wfloat-equal -Winit-self              \\
          -Wint-to-pointer-cast -Wlogical-op -Wmissing-braces -Wmissing-field-initializers       \\
          -Woverflow -Wpointer-arith -Wredundant-decls -Wreturn-type -Wshadow -Wsign-compare     \\
          -Wtype-limits -Wuninitialized -Wwrite-strings                                          \\
          -Wno-unused-parameter -Wno-unused-variable -Wno-multichar -Wno-unused-but-set-variable \\
          -Wdeclaration-after-statement -Wimplicit-int -Wjump-misses-init -Wpointer-sign         \\
          -Wpointer-to-int-cast -Wmissing-parameter-type
CXXWARN  =-Wall -Wextra -Wattributes -Wbuiltin-macro-redefined -Wcast-align -Wconversion         \\
          -Wdiv-by-zero -Wdouble-promotion -Wenum-compare -Wfloat-equal -Winit-self              \\
          -Wint-to-pointer-cast -Wlogical-op -Wmissing-braces -Wmissing-field-initializers       \\
          -Woverflow -Wpointer-arith -Wredundant-decls -Wreturn-type -Wshadow -Wsign-compare     \\
          -Wtype-limits -Wuninitialized -Wwrite-strings                                          \\
          -Wno-unused-parameter -Wno-unused-variable -Wno-multichar -Wno-unused-but-set-variable \\
          -Wc++0x-compat  -Wsign-promo

使用-Wextra或朋友的一些警告是开启的,但我只是想明确地将它们打开,如果命令行不太长就不会受到伤害。

对于Android和iOS,您可能还需要关闭一些警告以减少标准库中的噪音。

如果你可能想知道有很多标志太过分了,但它让编译器对任何糟糕的编程习惯都是诚实的,它可能不会来自你,也不会来自你的队友。