f78 Options to Request or Suppress Warnings Contents|Index|Previous|Next
 

Options to request or suppress warnings  

Warnings are diagnostic messages that report constructions which are not inherently erroneous; they may warn of risky constructions or constructions, actually, in error.

You can request many specific warnings with options beginning with ‘-W’; for instance, use ‘-Wimplicit’ to request warnings on implicit declarations. Each of these specific warning options also has a negative form beginning ‘-Wno-’ to turn off warnings; for instance, ‘-Wno-implicit’. This documentation discusses only one of the two forms, whichever is not the default.

The following options control the amount and kinds of warnings produced by GNU CC.
 

The remaining -W... options are not implied by -Wall. Some of them warn about constructions that users generally do not consider questionable, but which, on occasion, need to be checked for; others warn about constructions that are necessary or difficult to avoid in some cases, and for which there is no simple way to modify the code to suppress the warning.
    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.)
     
-Wstrict-prototypes
    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 which specifies the argument types.)
     
-Wmissing-prototypes
    Warn if a global function is defined without a previous prototype declaration. This warning is issued even if the definition itself provides a prototype. The aim is to detect global functions that fail to be declared in header files.
     
-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.
     
-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.
     
-Wnested-externs
    Warn if an extern declaration is encountered within a function.
     
-Winline
    Warn if a function can not be inlined, and either it was declared as inline, or else the -finline-functions option was given.
     
-Wold-style-cast
Warn if an old-style (C-style) cast is used within a program.
 
-Woverloaded-virtual
    Warn when a derived class function declaration may be an error in defining a virtual function (C++ only). In a derived class, the definitions of virtual functions must match the type signature of a virtual function declared in the base class. With this option, the compiler warns when you define a function with the same name as a virtual function, but with a type signature that does not match any declarations from the base class.
     
-Wsynth (C++ only)
    Warn when the g++ synthesis behavior does not match that of cfront. For instance:
      struct A { 
            operator int (); 
            A& operator = (int); 
      }; 
      
      main () 
      { 
            A a,b; 
            a =b; 
      }
    In this example, g++ will synthesize a default ‘A& operator = (const A&);’expression while cfront will use the user-defined ‘operator =’ expression.
     
-Wlong-long
Warn if long long type is used. This is default. To inhibit the warning messages, use -Wno-long-long. Flags -Wlong-long and -Wno-long-long are taken into account only when the -pedantic flag is used.
 
-Werror
    Make all warnings into errors.
0