c++ - How to turn on (literally) ALL of GCC's warnings? -


i enable -- literally -- all of warnings gcc has. (you'd think easy...)

  • you'd think -wall might trick, nope! still need -wextra.

  • you'd think -wextra might trick, nope! not of warnings listed here (for example, -wshadow) enabled this. , still have no idea if list comprehensive.

how tell gcc enable (no if's, and's, or but's!) all warnings has?

you can't.

the manual gcc 4.4.0 comprehensive version, list possible warnings 4.4.0. they're not on page link though, instance language-specific options on pages c++ options or obj-c options. find them you're better off looking @ options summary

turning on everything include -wdouble-promotion relevant on cpus 32-bit single-precision floating-point unit implements float in hardware, emulates double in software. doing calculations double use software emulation , slower. that's relevant embedded cpus, irrelevant modern desktop cpus hardware support 64-bit floating-point.

another warning that's not useful -wtraditional, warns formed code has different meaning (or doesn't work) in traditional c, e.g. "string " "concatenation", or iso c function definitions! care compatibility 30 year old compilers? want warning writing int inc(int i) { return i+1; } ?

i think -weffc++ noisy useful, it's based on outdated first edition of effective c++ , warns constructs valid c++ (and guidelines changed in later editions of book.) don't want warned haven't initialized std::string member in constructor; has default constructor want, why should write m_str() call it? -weffc++ warnings helpful difficult compiler detect accurately (giving false negatives), , ones aren't useful, such initializing members explicitly, produce noise, giving false positives.

luc danton provided great example of useless warnings -waggregate-return never makes sense c++ code.

i.e. don't want all warnings, think do.

go through manual, read them, decide might want enable, try them. reading compiler's manual thingtm anyway, taking short cut , enabling warnings don't understand not idea, if it's avoid having rtfm.

anyone turns on everything either doing because they're clueless because or pointy-haired boss said "no warnings."

some warnings important, , aren't. have discriminating or mess program. consider, instance, -wdouble-promotion. if you're working on embedded system might want this; if you're working on desktop system don't. , want -wtraditional? doubt it.

edit: see -wall-all enable warnings closed wontfix.

edit 2: in response devsolar's complaint makefiles needing use different warnings depending on compiler version, if -wall -wextra isn't suitable it's not difficult use compiler-specific , version-specific cflags:

compiler_name := $(notdir $(cc)) ifeq ($(compiler_name),gcc) compiler_version := $(basename $(shell $(cc) -dumpversion)) endif ifeq ($(compile_name),clang) compiler_version := $(shell $(cc) --version | awk 'nr==1{print $$3}') endif # ... wflags.gcc.base := -wall -wextra wflags.gcc.4.7 := -wzero-as-null-pointer-constant wflags.gcc.4.8 := $(wflags.gcc.4.7) wflags.clang.base := -wall -wextra wflags.clang.3.2 := -weverything cflags += $(wflags.$(compiler_name).base) $(wflags.$(compiler_name).$(compiler_version)) 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -