компилятор C и C ++ проекта GNU (GNU project C and C++ compiler)
Параметры подробно (Options detail)
Request or Suppress Warnings - 3
-Wunsafe-loop-optimizations
Warn if the loop cannot be optimized because the compiler
cannot assume anything on the bounds of the loop indices.
With -funsafe-loop-optimizations
warn if the compiler makes
such assumptions.
-Wno-pedantic-ms-format
(MinGW targets only)
When used in combination with -Wformat
and -pedantic
without
GNU extensions, this option disables the warnings about non-
ISO "printf" / "scanf" format width specifiers "I32", "I64",
and "I" used on Windows targets, which depend on the MS
runtime.
-Waligned-new
Warn about a new-expression of a type that requires greater
alignment than the "alignof(std::max_align_t)" but uses an
allocation function without an explicit alignment parameter.
This option is enabled by -Wall
.
Normally this only warns about global allocation functions,
but -Waligned-new=all
also warns about class member
allocation functions.
-Wplacement-new
-Wplacement-new=
n
Warn about placement new expressions with undefined behavior,
such as constructing an object in a buffer that is smaller
than the type of the object. For example, the placement new
expression below is diagnosed because it attempts to
construct an array of 64 integers in a buffer only 64 bytes
large.
char buf [64];
new (buf) int[64];
This warning is enabled by default.
-Wplacement-new=1
This is the default warning level of -Wplacement-new
. At
this level the warning is not issued for some strictly
undefined constructs that GCC allows as extensions for
compatibility with legacy code. For example, the
following "new" expression is not diagnosed at this level
even though it has undefined behavior according to the
C++ standard because it writes past the end of the one-
element array.
struct S { int n, a[1]; };
S *s = (S *)malloc (sizeof *s + 31 * sizeof s->a[0]);
new (s->a)int [32]();
-Wplacement-new=2
At this level, in addition to diagnosing all the same
constructs as at level 1, a diagnostic is also issued for
placement new expressions that construct an object in the
last member of structure whose type is an array of a
single element and whose size is less than the size of
the object being constructed. While the previous example
would be diagnosed, the following construct makes use of
the flexible member array extension to avoid the warning
at level 2.
struct S { int n, a[]; };
S *s = (S *)malloc (sizeof *s + 32 * sizeof s->a[0]);
new (s->a)int [32]();
-Wpointer-arith
Warn about anything that depends on the "size of" a function
type or of "void". GNU C assigns these types a size of 1,
for convenience in calculations with "void *" pointers and
pointers to functions. In C++, warn also when an arithmetic
operation involves "NULL". This warning is also enabled by
-Wpedantic
.
-Wpointer-compare
Warn if a pointer is compared with a zero character constant.
This usually means that the pointer was meant to be
dereferenced. For example:
const char *p = foo ();
if (p == '\0')
return 42;
Note that the code above is invalid in C++11.
This warning is enabled by default.
-Wtype-limits
Warn if a comparison is always true or always false due to
the limited range of the data type, but do not warn for
constant expressions. For example, warn if an unsigned
variable is compared against zero with "<" or ">=". This
warning is also enabled by -Wextra
.
-Wabsolute-value
(C and Objective-C only)
Warn for calls to standard functions that compute the
absolute value of an argument when a more appropriate
standard function is available. For example, calling
"abs(3.14)" triggers the warning because the appropriate
function to call to compute the absolute value of a double
argument is "fabs". The option also triggers warnings when
the argument in a call to such a function has an unsigned
type. This warning can be suppressed with an explicit type
cast and it is also enabled by -Wextra
.
-Wcomment
-Wcomments
Warn whenever a comment-start sequence /*
appears in a /*
comment, or whenever a backslash-newline appears in a //
comment. This warning is enabled by -Wall
.
-Wtrigraphs
Warn if any trigraphs are encountered that might change the
meaning of the program. Trigraphs within comments are not
warned about, except those that would form escaped newlines.
This option is implied by -Wall
. If -Wall
is not given, this
option is still enabled unless trigraphs are enabled. To get
trigraph conversion without warnings, but get the other -Wall
warnings, use -trigraphs -Wall -Wno-trigraphs
.
-Wundef
Warn if an undefined identifier is evaluated in an "#if"
directive. Such identifiers are replaced with zero.
-Wexpansion-to-defined
Warn whenever defined
is encountered in the expansion of a
macro (including the case where the macro is expanded by an
#if
directive). Such usage is not portable. This warning is
also enabled by -Wpedantic
and -Wextra
.
-Wunused-macros
Warn about macros defined in the main file that are unused.
A macro is used if it is expanded or tested for existence at
least once. The preprocessor also warns if the macro has not
been used at the time it is redefined or undefined.
Built-in macros, macros defined on the command line, and
macros defined in include files are not warned about.
Note: If a macro is actually used, but only used in skipped
conditional blocks, then the preprocessor reports it as
unused. To avoid the warning in such a case, you might
improve the scope of the macro's definition by, for example,
moving it into the first skipped block. Alternatively, you
could provide a dummy use with something like:
#if defined the_macro_causing_the_warning
#endif
-Wno-endif-labels
Do not warn whenever an "#else" or an "#endif" are followed
by text. This sometimes happens in older programs with code
of the form
#if FOO
...
#else FOO
...
#endif FOO
The second and third "FOO" should be in comments. This
warning is on by default.
-Wbad-function-cast
(C and Objective-C only)
Warn when a function call is cast to a non-matching type.
For example, warn if a call to a function returning an
integer type is cast to a pointer type.
-Wc90-c99-compat
(C and Objective-C only)
Warn about features not present in ISO C90, but present in
ISO C99. For instance, warn about use of variable length
arrays, "long long" type, "bool" type, compound literals,
designated initializers, and so on. This option is
independent of the standards mode. Warnings are disabled in
the expression that follows "__extension__".
-Wc99-c11-compat
(C and Objective-C only)
Warn about features not present in ISO C99, but present in
ISO C11. For instance, warn about use of anonymous
structures and unions, "_Atomic" type qualifier,
"_Thread_local" storage-class specifier, "_Alignas"
specifier, "Alignof" operator, "_Generic" keyword, and so on.
This option is independent of the standards mode. Warnings
are disabled in the expression that follows "__extension__".
-Wc11-c2x-compat
(C and Objective-C only)
Warn about features not present in ISO C11, but present in
ISO C2X. For instance, warn about omitting the string in
"_Static_assert". This option is independent of the
standards mode. Warnings are disabled in the expression that
follows "__extension__".
-Wc++-compat
(C and Objective-C only)
Warn about ISO C constructs that are outside of the common
subset of ISO C and ISO C++, e.g. request for implicit
conversion from "void *" to a pointer to non-"void" type.
-Wc++11-compat
(C++ and Objective-C++ only)
Warn about C++ constructs whose meaning differs between ISO
C++ 1998 and ISO C++ 2011, e.g., identifiers in ISO C++ 1998
that are keywords in ISO C++ 2011. This warning turns on
-Wnarrowing
and is enabled by -Wall
.
-Wc++14-compat
(C++ and Objective-C++ only)
Warn about C++ constructs whose meaning differs between ISO
C++ 2011 and ISO C++ 2014. This warning is enabled by -Wall
.
-Wc++17-compat
(C++ and Objective-C++ only)
Warn about C++ constructs whose meaning differs between ISO
C++ 2014 and ISO C++ 2017. This warning is enabled by -Wall
.
-Wcast-qual
Warn whenever a pointer is cast so as to remove a type
qualifier from the target type. For example, warn if a
"const char *" is cast to an ordinary "char *".
Also warn when making a cast that introduces a type qualifier
in an unsafe way. For example, casting "char **" to "const
char **" is unsafe, as in this example:
/* p is char ** value. */
const char **q = (const char **) p;
/* Assignment of readonly string to const char * is OK. */
*q = "string";
/* Now char** pointer points to read-only memory. */
**p = 'b';
-Wcast-align
Warn 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-align=strict
Warn 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 *" regardless of the target
machine.
-Wcast-function-type
Warn when a function pointer is cast to an incompatible
function pointer. In a cast involving function types with a
variable argument list only the types of initial arguments
that are provided are considered. Any parameter of pointer-
type matches any other pointer-type. Any benign differences
in integral types are ignored, like "int" vs. "long" on ILP32
targets. Likewise type qualifiers are ignored. The function
type "void (*) (void)" is special and matches everything,
which can be used to suppress this warning. In a cast
involving pointer to member types this warning warns whenever
the type cast is changing the pointer to member type. This
warning is enabled by -Wextra
.
-Wwrite-strings
When compiling C, give string constants the type "const
char[length]" so that copying the address of one into a
non-"const" "char *" pointer produces a warning. These
warnings help you find at compile time code that can try to
write into a string constant, but only if you have been very
careful about using "const" in declarations and prototypes.
Otherwise, it is just a nuisance. This is why we did not make
-Wall
request these warnings.
When compiling C++, warn about the deprecated conversion from
string literals to "char *". This warning is enabled by
default for C++ programs.
-Wcatch-value
-Wcatch-value=
n (C++ and Objective-C++ only)
Warn about catch handlers that do not catch via reference.
With -Wcatch-value=1
(or -Wcatch-value
for short) warn about
polymorphic class types that are caught by value. With
-Wcatch-value=2
warn about all class types that are caught by
value. With -Wcatch-value=3
warn about all types that are not
caught by reference. -Wcatch-value
is enabled by -Wall
.
-Wclobbered
Warn for variables that might be changed by "longjmp" or
"vfork". This warning is also enabled by -Wextra
.
-Wconditionally-supported
(C++ and Objective-C++ only)
Warn for conditionally-supported (C++11 [intro.defs])
constructs.
-Wconversion
Warn for implicit conversions that may alter a value. This
includes conversions between real and integer, like "abs (x)"
when "x" is "double"; conversions between signed and
unsigned, like "unsigned ui = -1"; and conversions to smaller
types, like "sqrtf (M_PI)". Do not warn for explicit casts
like "abs ((int) x)" and "ui = (unsigned) -1", or if the
value is not changed by the conversion like in "abs (2.0)".
Warnings about conversions between signed and unsigned
integers can be disabled by using -Wno-sign-conversion
.
For C++, also warn for confusing overload resolution for
user-defined conversions; and conversions that never use a
type conversion operator: conversions to "void", the same
type, a base class or a reference to them. Warnings about
conversions between signed and unsigned integers are disabled
by default in C++ unless -Wsign-conversion
is explicitly
enabled.
-Wno-conversion-null
(C++ and Objective-C++ only)
Do not warn for conversions between "NULL" and non-pointer
types. -Wconversion-null
is enabled by default.
-Wzero-as-null-pointer-constant
(C++ and Objective-C++ only)
Warn when a literal 0
is used as null pointer constant. This
can be useful to facilitate the conversion to "nullptr" in
C++11.
-Wsubobject-linkage
(C++ and Objective-C++ only)
Warn if a class type has a base or a field whose type uses
the anonymous namespace or depends on a type with no linkage.
If a type A depends on a type B with no or internal linkage,
defining it in multiple translation units would be an ODR
violation because the meaning of B is different in each
translation unit. If A only appears in a single translation
unit, the best way to silence the warning is to give it
internal linkage by putting it in an anonymous namespace as
well. The compiler doesn't give this warning for types
defined in the main .C file, as those are unlikely to have
multiple definitions. -Wsubobject-linkage
is enabled by
default.
-Wdangling-else
Warn about constructions where there may be confusion to
which "if" statement an "else" branch belongs. Here is an
example of such a case:
{
if (a)
if (b)
foo ();
else
bar ();
}
In C/C++, every "else" branch belongs to the innermost
possible "if" statement, which in this example is "if (b)".
This is often not what the programmer expected, as
illustrated in the above example by indentation the
programmer chose. When there is the potential for this
confusion, GCC issues a warning when this flag is specified.
To eliminate the warning, add explicit braces around the
innermost "if" statement so there is no way the "else" can
belong to the enclosing "if". The resulting code looks like
this:
{
if (a)
{
if (b)
foo ();
else
bar ();
}
}
This warning is enabled by -Wparentheses
.
-Wdate-time
Warn when macros "__TIME__", "__DATE__" or "__TIMESTAMP__"
are encountered as they might prevent bit-wise-identical
reproducible compilations.
-Wdelete-incomplete
(C++ and Objective-C++ only)
Warn when deleting a pointer to incomplete type, which may
cause undefined behavior at runtime. This warning is enabled
by default.
-Wuseless-cast
(C++ and Objective-C++ only)
Warn when an expression is casted to its own type.
-Wempty-body
Warn if an empty body occurs in an "if", "else" or "do while"
statement. This warning is also enabled by -Wextra
.
-Wenum-compare
Warn about a comparison between values of different
enumerated types. In C++ enumerated type mismatches in
conditional expressions are also diagnosed and the warning is
enabled by default. In C this warning is enabled by -Wall
.
-Wextra-semi
(C++, Objective-C++ only)
Warn about redundant semicolon after in-class function
definition.
-Wjump-misses-init
(C, Objective-C only)
Warn if a "goto" statement or a "switch" statement jumps
forward across the initialization of a variable, or jumps
backward to a label after the variable has been initialized.
This only warns about variables that are initialized when
they are declared. This warning is only supported for C and
Objective-C; in C++ this sort of branch is an error in any
case.
-Wjump-misses-init
is included in -Wc++-compat
. It can be
disabled with the -Wno-jump-misses-init
option.
-Wsign-compare
Warn when a comparison between signed and unsigned values
could produce an incorrect result when the signed value is
converted to unsigned. In C++, this warning is also enabled
by -Wall
. In C, it is also enabled by -Wextra
.
-Wsign-conversion
Warn for implicit conversions that may change the sign of an
integer value, like assigning a signed integer expression to
an unsigned integer variable. An explicit cast silences the
warning. In C, this option is enabled also by -Wconversion
.
-Wfloat-conversion
Warn for implicit conversions that reduce the precision of a
real value. This includes conversions from real to integer,
and from higher precision real to lower precision real
values. This option is also enabled by -Wconversion
.
-Wno-scalar-storage-order
Do not warn on suspicious constructs involving reverse scalar
storage order.
-Wsized-deallocation
(C++ and Objective-C++ only)
Warn about a definition of an unsized deallocation function
void operator delete (void *) noexcept;
void operator delete[] (void *) noexcept;
without a definition of the corresponding sized deallocation
function
void operator delete (void *, std::size_t) noexcept;
void operator delete[] (void *, std::size_t) noexcept;
or vice versa. Enabled by -Wextra
along with
-fsized-deallocation
.
-Wsizeof-pointer-div
Warn for suspicious divisions of two sizeof expressions that
divide the pointer size by the element size, which is the
usual way to compute the array size but won't work out
correctly with pointers. This warning warns e.g. about
"sizeof (ptr) / sizeof (ptr[0])" if "ptr" is not an array,
but a pointer. This warning is enabled by -Wall
.
-Wsizeof-pointer-memaccess
Warn for suspicious length parameters to certain string and
memory built-in functions if the argument uses "sizeof".
This warning triggers for example for "memset (ptr, 0, sizeof
(ptr));" if "ptr" is not an array, but a pointer, and
suggests a possible fix, or about "memcpy (&foo, ptr, sizeof
(&foo));". -Wsizeof-pointer-memaccess
also warns about calls
to bounded string copy functions like "strncat" or "strncpy"
that specify as the bound a "sizeof" expression of the source
array. For example, in the following function the call to
"strncat" specifies the size of the source string as the
bound. That is almost certainly a mistake and so the call is
diagnosed.
void make_file (const char *name)
{
char path[PATH_MAX];
strncpy (path, name, sizeof path - 1);
strncat (path, ".text", sizeof ".text");
...
}
The -Wsizeof-pointer-memaccess
option is enabled by -Wall
.
-Wsizeof-array-argument
Warn when the "sizeof" operator is applied to a parameter
that is declared as an array in a function definition. This
warning is enabled by default for C and C++ programs.
-Wmemset-elt-size
Warn for suspicious calls to the "memset" built-in function,
if the first argument references an array, and the third
argument is a number equal to the number of elements, but not
equal to the size of the array in memory. This indicates
that the user has omitted a multiplication by the element
size. This warning is enabled by -Wall
.
-Wmemset-transposed-args
Warn for suspicious calls to the "memset" built-in function
where the second argument is not zero and the third argument
is zero. For example, the call "memset (buf, sizeof buf, 0)"
is diagnosed because "memset (buf, 0, sizeof buf)" was meant
instead. The diagnostic is only emitted if the third
argument is a literal zero. Otherwise, if it is an
expression that is folded to zero, or a cast of zero to some
type, it is far less likely that the arguments have been
mistakenly transposed and no warning is emitted. This
warning is enabled by -Wall
.
-Waddress
Warn about suspicious uses of memory addresses. These include
using the address of a function in a conditional expression,
such as "void func(void); if (func)", and comparisons against
the memory address of a string literal, such as "if (x ==
"abc")". Such uses typically indicate a programmer error:
the address of a function always evaluates to true, so their
use in a conditional usually indicate that the programmer
forgot the parentheses in a function call; and comparisons
against string literals result in unspecified behavior and
are not portable in C, so they usually indicate that the
programmer intended to use "strcmp". This warning is enabled
by -Wall
.
-Waddress-of-packed-member
Warn when the address of packed member of struct or union is
taken, which usually results in an unaligned pointer value.
This is enabled by default.
-Wlogical-op
Warn about suspicious uses of logical operators in
expressions. This includes using logical operators in
contexts where a bit-wise operator is likely to be expected.
Also warns when the operands of a logical operator are the
same:
extern int a;
if (a < 0 && a < 0) { ... }
-Wlogical-not-parentheses
Warn about logical not used on the left hand side operand of
a comparison. This option does not warn if the right operand
is considered to be a boolean expression. Its purpose is to
detect suspicious code like the following:
int a;
...
if (!a > 1) { ... }
It is possible to suppress the warning by wrapping the LHS
into parentheses:
if ((!a) > 1) { ... }
This warning is enabled by -Wall
.
-Waggregate-return
Warn if any functions that return structures or unions are
defined or called. (In languages where you can return an
array, this also elicits a warning.)
-Wno-aggressive-loop-optimizations
Warn if in a loop with constant number of iterations the
compiler detects undefined behavior in some statement during
one or more of the iterations.
-Wno-attributes
Do not warn if an unexpected "__attribute__" is used, such as
unrecognized attributes, function attributes applied to
variables, etc. This does not stop errors for incorrect use
of supported attributes.
-Wno-builtin-declaration-mismatch
Warn if a built-in function is declared with an incompatible
signature or as a non-function, or when a built-in function
declared with a type that does not include a prototype is
called with arguments whose promoted types do not match those
expected by the function. When -Wextra
is specified, also
warn when a built-in function that takes arguments is
declared without a prototype. The
-Wno-builtin-declaration-mismatch
warning is enabled by
default. To avoid the warning include the appropriate header
to bring the prototypes of built-in functions into scope.
For example, the call to "memset" below is diagnosed by the
warning because the function expects a value of type "size_t"
as its argument but the type of 32 is "int". With -Wextra
,
the declaration of the function is diagnosed as well.
extern void* memset ();
void f (void *d)
{
memset (d, '\0', 32);
}
-Wno-builtin-macro-redefined
Do not warn if certain built-in macros are redefined. This
suppresses warnings for redefinition of "__TIMESTAMP__",
"__TIME__", "__DATE__", "__FILE__", and "__BASE_FILE__".
-Wstrict-prototypes
(C and Objective-C only)
Warn if a function is declared or defined without specifying
the argument types. (An old-style function definition is
permitted without a warning if preceded by a declaration that
specifies the argument types.)
-Wold-style-declaration
(C and Objective-C only)
Warn for obsolescent usages, according to the C Standard, in
a declaration. For example, warn if storage-class specifiers
like "static" are not the first things in a declaration.
This warning is also enabled by -Wextra
.
-Wold-style-definition
(C and Objective-C only)
Warn if an old-style function definition is used. A warning
is given even if there is a previous prototype.
-Wmissing-parameter-type
(C and Objective-C only)
A function parameter is declared without a type specifier in
K&R-style functions:
void foo(bar) { }
This warning is also enabled by -Wextra
.
-Wmissing-prototypes
(C and Objective-C only)
Warn if a global function is defined without a previous
prototype declaration. This warning is issued even if the
definition itself provides a prototype. Use this option to
detect global functions that do not have a matching prototype
declaration in a header file. This option is not valid for
C++ because all function declarations provide prototypes and
a non-matching declaration declares an overload rather than
conflict with an earlier declaration. Use
-Wmissing-declarations
to detect missing declarations in C++.
-Wmissing-declarations
Warn if a global function is defined without a previous
declaration. Do so even if the definition itself provides a
prototype. Use this option to detect global functions that
are not declared in header files. In C, no warnings are
issued for functions with previous non-prototype
declarations; use -Wmissing-prototypes
to detect missing
prototypes. In C++, no warnings are issued for function
templates, or for inline functions, or for functions in
anonymous namespaces.
-Wmissing-field-initializers
Warn if a structure's initializer has some fields missing.
For example, the following code causes such a warning,
because "x.h" is implicitly zero:
struct s { int f, g, h; };
struct s x = { 3, 4 };
This option does not warn about designated initializers, so
the following modification does not trigger a warning:
struct s { int f, g, h; };
struct s x = { .f = 3, .g = 4 };
In C this option does not warn about the universal zero
initializer { 0 }
:
struct s { int f, g, h; };
struct s x = { 0 };
Likewise, in C++ this option does not warn about the empty {
} initializer, for example:
struct s { int f, g, h; };
s x = { };
This warning is included in -Wextra
. To get other -Wextra
warnings without this one, use -Wextra
-Wno-missing-field-initializers
.
-Wno-multichar
Do not warn if a multicharacter constant ('FOOF'
) is used.
Usually they indicate a typo in the user's code, as they have
implementation-defined values, and should not be used in
portable code.
-Wnormalized=
[none
|id
|nfc
|nfkc
]
In ISO C and ISO C++, two identifiers are different if they
are different sequences of characters. However, sometimes
when characters outside the basic ASCII character set are
used, you can have two different character sequences that
look the same. To avoid confusion, the ISO 10646 standard
sets out some normalization rules which when applied ensure
that two sequences that look the same are turned into the
same sequence. GCC can warn you if you are using identifiers
that have not been normalized; this option controls that
warning.
There are four levels of warning supported by GCC. The
default is -Wnormalized=nfc
, which warns about any identifier
that is not in the ISO 10646 "C" normalized form, NFC. NFC
is the recommended form for most uses. It is equivalent to
-Wnormalized
.
Unfortunately, there are some characters allowed in
identifiers by ISO C and ISO C++ that, when turned into NFC,
are not allowed in identifiers. That is, there's no way to
use these symbols in portable ISO C or C++ and have all your
identifiers in NFC. -Wnormalized=id
suppresses the warning
for these characters. It is hoped that future versions of
the standards involved will correct this, which is why this
option is not the default.
You can switch the warning off for all characters by writing
-Wnormalized=none
or -Wno-normalized
. You should only do
this if you are using some other normalization scheme (like
"D"), because otherwise you can easily create bugs that are
literally impossible to see.
Some characters in ISO 10646 have distinct meanings but look
identical in some fonts or display methodologies, especially
once formatting has been applied. For instance "\u207F",
"SUPERSCRIPT LATIN SMALL LETTER N", displays just like a
regular "n" that has been placed in a superscript. ISO 10646
defines the NFKC normalization scheme to convert all these
into a standard form as well, and GCC warns if your code is
not in NFKC if you use -Wnormalized=nfkc
. This warning is
comparable to warning about every identifier that contains
the letter O because it might be confused with the digit 0,
and so is not the default, but may be useful as a local
coding convention if the programming environment cannot be
fixed to display these characters distinctly.
-Wno-attribute-warning
Do not warn about usage of functions declared with "warning"
attribute. By default, this warning is enabled.
-Wno-attribute-warning
can be used to disable the warning or
-Wno-error=attribute-warning
can be used to disable the error
when compiled with -Werror
flag.
-Wno-deprecated
Do not warn about usage of deprecated features.
-Wno-deprecated-declarations
Do not warn about uses of functions, variables, and types
marked as deprecated by using the "deprecated" attribute.
-Wno-overflow
Do not warn about compile-time overflow in constant
expressions.
-Wno-odr
Warn about One Definition Rule violations during link-time
optimization. Requires -flto-odr-type-merging
to be enabled.
Enabled by default.
-Wopenmp-simd
Warn if the vectorizer cost model overrides the OpenMP simd
directive set by user. The -fsimd-cost-model=unlimited
option can be used to relax the cost model.
-Woverride-init
(C and Objective-C only)
Warn if an initialized field without side effects is
overridden when using designated initializers.
This warning is included in -Wextra
. To get other -Wextra
warnings without this one, use -Wextra -Wno-override-init
.
-Woverride-init-side-effects
(C and Objective-C only)
Warn if an initialized field with side effects is overridden
when using designated initializers. This warning is enabled
by default.
-Wpacked
Warn if a structure is given the packed attribute, but the
packed attribute has no effect on the layout or size of the
structure. Such structures may be mis-aligned for little
benefit. For instance, in this code, the variable "f.x" in
"struct bar" is misaligned even though "struct bar" does not
itself have the packed attribute:
struct foo {
int x;
char a, b, c, d;
} __attribute__((packed));
struct bar {
char z;
struct foo f;
};
-Wpacked-bitfield-compat
The 4.1, 4.2 and 4.3 series of GCC ignore the "packed"
attribute on bit-fields of type "char". This has been fixed
in GCC 4.4 but the change can lead to differences in the
structure layout. GCC informs you when the offset of such a
field has changed in GCC 4.4. For example there is no longer
a 4-bit padding between field "a" and "b" in this structure:
struct foo
{
char a:4;
char b:8;
} __attribute__ ((packed));
This warning is enabled by default. Use
-Wno-packed-bitfield-compat
to disable this warning.
-Wpacked-not-aligned
(C, C++, Objective-C and Objective-C++ only)
Warn if a structure field with explicitly specified alignment
in a packed struct or union is misaligned. For example, a
warning will be issued on "struct S", like, "warning:
alignment 1 of 'struct S' is less than 8", in this code:
struct __attribute__ ((aligned (8))) S8 { char a[8]; };
struct __attribute__ ((packed)) S {
struct S8 s8;
};
This warning is enabled by -Wall
.
-Wpadded
Warn if padding is included in a structure, either to align
an element of the structure or to align the whole structure.
Sometimes when this happens it is possible to rearrange the
fields of the structure to reduce the padding and so make the
structure smaller.
-Wredundant-decls
Warn if anything is declared more than once in the same
scope, even in cases where multiple declaration is valid and
changes nothing.
-Wno-restrict
Warn when an object referenced by a "restrict"-qualified
parameter (or, in C++, a "__restrict"-qualified parameter) is
aliased by another argument, or when copies between such
objects overlap. For example, the call to the "strcpy"
function below attempts to truncate the string by replacing
its initial characters with the last four. However, because
the call writes the terminating NUL into "a[4]", the copies
overlap and the call is diagnosed.
void foo (void)
{
char a[] = "abcd1234";
strcpy (a, a + 4);
...
}
The -Wrestrict
option detects some instances of simple
overlap even without optimization but works best at -O2
and
above. It is included in -Wall
.
-Wnested-externs
(C and Objective-C only)
Warn if an "extern" declaration is encountered within a
function.
-Wno-inherited-variadic-ctor
Suppress warnings about use of C++11 inheriting constructors
when the base class inherited from has a C variadic
constructor; the warning is on by default because the
ellipsis is not inherited.
-Winline
Warn if a function that is declared as inline cannot be
inlined. Even with this option, the compiler does not warn
about failures to inline functions declared in system
headers.
The compiler uses a variety of heuristics to determine
whether or not to inline a function. For example, the
compiler takes into account the size of the function being
inlined and the amount of inlining that has already been done
in the current function. Therefore, seemingly insignificant
changes in the source program can cause the warnings produced
by -Winline
to appear or disappear.
-Wno-invalid-offsetof
(C++ and Objective-C++ only)
Suppress warnings from applying the "offsetof" macro to a
non-POD type. According to the 2014 ISO C++ standard,
applying "offsetof" to a non-standard-layout type is
undefined. In existing C++ implementations, however,
"offsetof" typically gives meaningful results. This flag is
for users who are aware that they are writing nonportable
code and who have deliberately chosen to ignore the warning
about it.
The restrictions on "offsetof" may be relaxed in a future
version of the C++ standard.
-Wint-in-bool-context
Warn for suspicious use of integer values where boolean
values are expected, such as conditional expressions (?:)
using non-boolean integer constants in boolean context, like
"if (a <= b ? 2 : 3)". Or left shifting of signed integers
in boolean context, like "for (a = 0; 1 << a; a++);".
Likewise for all kinds of multiplications regardless of the
data type. This warning is enabled by -Wall
.
-Wno-int-to-pointer-cast
Suppress warnings from casts to pointer type of an integer of
a different size. In C++, casting to a pointer type of
smaller size is an error. Wint-to-pointer-cast
is enabled by
default.
-Wno-pointer-to-int-cast
(C and Objective-C only)
Suppress warnings from casts from a pointer to an integer
type of a different size.
-Winvalid-pch
Warn if a precompiled header is found in the search path but
cannot be used.
-Wlong-long
Warn if "long long" type is used. This is enabled by either
-Wpedantic
or -Wtraditional
in ISO C90 and C++98 modes. To
inhibit the warning messages, use -Wno-long-long
.
-Wvariadic-macros
Warn if variadic macros are used in ISO C90 mode, or if the
GNU alternate syntax is used in ISO C99 mode. This is
enabled by either -Wpedantic
or -Wtraditional
. To inhibit
the warning messages, use -Wno-variadic-macros
.
-Wvarargs
Warn upon questionable usage of the macros used to handle
variable arguments like "va_start". This is default. To
inhibit the warning messages, use -Wno-varargs
.
-Wvector-operation-performance
Warn if vector operation is not implemented via SIMD
capabilities of the architecture. Mainly useful for the
performance tuning. Vector operation can be implemented
"piecewise", which means that the scalar operation is
performed on every vector element; "in parallel", which means
that the vector operation is implemented using scalars of
wider type, which normally is more performance efficient; and
"as a single scalar", which means that vector fits into a
scalar type.
-Wno-virtual-move-assign
Suppress warnings about inheriting from a virtual base with a
non-trivial C++11 move assignment operator. This is
dangerous because if the virtual base is reachable along more
than one path, it is moved multiple times, which can mean
both objects end up in the moved-from state. If the move
assignment operator is written to avoid moving from a moved-
from object, this warning can be disabled.
-Wvla
Warn if a variable-length array is used in the code.
-Wno-vla
prevents the -Wpedantic
warning of the variable-
length array.
-Wvla-larger-than=
byte-size
If this option is used, the compiler will warn for
declarations of variable-length arrays whose size is either
unbounded, or bounded by an argument that allows the array
size to exceed byte-size bytes. This is similar to how
-Walloca-larger-than=
byte-size works, but with variable-
length arrays.
Note that GCC may optimize small variable-length arrays of a
known value into plain arrays, so this warning may not get
triggered for such arrays.
-Wvla-larger-than=PTRDIFF_MAX
is enabled by default but is
typically only effective when -ftree-vrp
is active (default
for -O2
and above).
See also -Walloca-larger-than=
byte-size.
-Wno-vla-larger-than
Disable -Wvla-larger-than=
warnings. The option is
equivalent to -Wvla-larger-than=SIZE_MAX
or larger.
-Wvolatile-register-var
Warn if a register variable is declared volatile. The
volatile modifier does not inhibit all optimizations that may
eliminate reads and/or writes to register variables. This
warning is enabled by -Wall
.
-Wdisabled-optimization
Warn if a requested optimization pass is disabled. This
warning does not generally indicate that there is anything
wrong with your code; it merely indicates that GCC's
optimizers are unable to handle the code effectively. Often,
the problem is that your code is too big or too complex; GCC
refuses to optimize programs when the optimization itself is
likely to take inordinate amounts of time.
-Wpointer-sign
(C and Objective-C only)
Warn for pointer argument passing or assignment with
different signedness. This option is only supported for C
and Objective-C. It is implied by -Wall
and by -Wpedantic
,
which can be disabled with -Wno-pointer-sign
.
-Wstack-protector
This option is only active when -fstack-protector
is active.
It warns about functions that are not protected against stack
smashing.
-Woverlength-strings
Warn about string constants that are longer than the "minimum
maximum" length specified in the C standard. Modern
compilers generally allow string constants that are much
longer than the standard's minimum limit, but very portable
programs should avoid using longer strings.
The limit applies after string constant concatenation, and
does not count the trailing NUL. In C90, the limit was 509
characters; in C99, it was raised to 4095. C++98 does not
specify a normative minimum maximum, so we do not diagnose
overlength strings in C++.
This option is implied by -Wpedantic
, and can be disabled
with -Wno-overlength-strings
.
-Wunsuffixed-float-constants
(C and Objective-C only)
Issue a warning for any floating constant that does not have
a suffix. When used together with -Wsystem-headers
it warns
about such constants in system header files. This can be
useful when preparing code to use with the
"FLOAT_CONST_DECIMAL64" pragma from the decimal floating-
point extension to C99.
-Wno-designated-init
(C and Objective-C only)
Suppress warnings when a positional initializer is used to
initialize a structure that has been marked with the
"designated_init" attribute.
-Whsa
Issue a warning when HSAIL cannot be emitted for the compiled
function or OpenMP construct.