Many projects enable additional diagnostics by using the -Wall
and -Wextra
command-line options.
Some projects even turn them into errors via -Werror
as their first line of defense.
-Wunused-macros
-Wempty-body
detects if or for statements with no body-Wsizeof-array-argument
detects applying the sizeof operator to a function parameter declared using the array-Wmissing-parameter-type
detects declaring function parameters without specifying their type-Wint-to-pointer-cast
and -Wpointer-to-int-cast
-Wsign-compare
detects comparisons between expressions with different signedness.-Wcast-qual
-Wcast-align
warns whenever a pointer is cast such that the required alignment of the target is increased.
For example, warn if a char * is cast to an int * on machines where integers can only be accessed at two- or four-byte boundaries.-Wcast-function-type
warns when a function pointer is cast to an incompatible function pointer.
The function type void (*) (void) is special and matches everything, which can be used to suppress this warning.-Wunused-value
, -Wunused-result
, and -Wunused-function
-Wshift-count-negative
, -Wshift-count-overflow
, -Wshift-negative-value
, and -Wshift-overflow
Also called flow-based warnings.
-Warray-bounds
detects out-of-bounds array indices-Wformat-overflow
looks for buffer overflows in calls to sprintf and related functions-Wnonnull
detects passing null pointers to functions that don’t expect it-Wstringop-overflow
helps find buffer overflow in calls to string and raw memory functions-Wuninitialized
finds uses of uninitialized variablesC
CPP
Written on
November
7th,
2021
by
Borting