gcc: C++ Dialect Options

1 
1 3.5 Options Controlling C++ Dialect
1 ===================================
1 
1 This section describes the command-line options that are only meaningful
1 for C++ programs.  You can also use most of the GNU compiler options
1 regardless of what language your program is in.  For example, you might
1 compile a file 'firstClass.C' like this:
1 
1      g++ -g -fstrict-enums -O -c firstClass.C
1 
1 In this example, only '-fstrict-enums' is an option meant only for C++
1 programs; you can use the other options with any language supported by
1 GCC.
1 
1  Some options for compiling C programs, such as '-std', are also
11 relevant for C++ programs.  ⇒Options Controlling C Dialect C
 Dialect Options.
1 
1  Here is a list of options that are _only_ for compiling C++ programs:
1 
1 '-fabi-version=N'
1      Use version N of the C++ ABI.  The default is version 0.
1 
1      Version 0 refers to the version conforming most closely to the C++
1      ABI specification.  Therefore, the ABI obtained using version 0
1      will change in different versions of G++ as ABI bugs are fixed.
1 
1      Version 1 is the version of the C++ ABI that first appeared in G++
1      3.2.
1 
1      Version 2 is the version of the C++ ABI that first appeared in G++
1      3.4, and was the default through G++ 4.9.
1 
1      Version 3 corrects an error in mangling a constant address as a
1      template argument.
1 
1      Version 4, which first appeared in G++ 4.5, implements a standard
1      mangling for vector types.
1 
1      Version 5, which first appeared in G++ 4.6, corrects the mangling
1      of attribute const/volatile on function pointer types, decltype of
1      a plain decl, and use of a function parameter in the declaration of
1      another parameter.
1 
1      Version 6, which first appeared in G++ 4.7, corrects the promotion
1      behavior of C++11 scoped enums and the mangling of template
1      argument packs, const/static_cast, prefix ++ and -, and a class
1      scope function used as a template argument.
1 
1      Version 7, which first appeared in G++ 4.8, that treats nullptr_t
1      as a builtin type and corrects the mangling of lambdas in default
1      argument scope.
1 
1      Version 8, which first appeared in G++ 4.9, corrects the
1      substitution behavior of function types with
1      function-cv-qualifiers.
1 
1      Version 9, which first appeared in G++ 5.2, corrects the alignment
1      of 'nullptr_t'.
1 
1      Version 10, which first appeared in G++ 6.1, adds mangling of
1      attributes that affect type identity, such as ia32 calling
1      convention attributes (e.g.  'stdcall').
1 
1      Version 11, which first appeared in G++ 7, corrects the mangling of
1      sizeof...  expressions and operator names.  For multiple entities
1      with the same name within a function, that are declared in
1      different scopes, the mangling now changes starting with the
1      twelfth occurrence.  It also implies '-fnew-inheriting-ctors'.
1 
1      Version 12, which first appeared in G++ 8, corrects the calling
1      conventions for empty classes on the x86_64 target and for classes
1      with only deleted copy/move constructors.  It accidentally changes
1      the calling convention for classes with a deleted copy constructor
1      and a trivial move constructor.
1 
1      Version 13, which first appeared in G++ 8.2, fixes the accidental
1      change in version 12.
1 
1      See also '-Wabi'.
1 
1 '-fabi-compat-version=N'
1      On targets that support strong aliases, G++ works around mangling
1      changes by creating an alias with the correct mangled name when
1      defining a symbol with an incorrect mangled name.  This switch
1      specifies which ABI version to use for the alias.
1 
1      With '-fabi-version=0' (the default), this defaults to 11 (GCC 7
1      compatibility).  If another ABI version is explicitly selected,
1      this defaults to 0.  For compatibility with GCC versions 3.2
1      through 4.9, use '-fabi-compat-version=2'.
1 
1      If this option is not provided but '-Wabi=N' is, that version is
1      used for compatibility aliases.  If this option is provided along
1      with '-Wabi' (without the version), the version from this option is
1      used for the warning.
1 
1 '-fno-access-control'
1      Turn off all access checking.  This switch is mainly useful for
1      working around bugs in the access control code.
1 
1 '-faligned-new'
1      Enable support for C++17 'new' of types that require more alignment
1      than 'void* ::operator new(std::size_t)' provides.  A numeric
1      argument such as '-faligned-new=32' can be used to specify how much
1      alignment (in bytes) is provided by that function, but few users
1      will need to override the default of 'alignof(std::max_align_t)'.
1 
1      This flag is enabled by default for '-std=c++17'.
1 
1 '-fcheck-new'
1      Check that the pointer returned by 'operator new' is non-null
1      before attempting to modify the storage allocated.  This check is
1      normally unnecessary because the C++ standard specifies that
1      'operator new' only returns '0' if it is declared 'throw()', in
1      which case the compiler always checks the return value even without
1      this option.  In all other cases, when 'operator new' has a
1      non-empty exception specification, memory exhaustion is signalled
1      by throwing 'std::bad_alloc'.  See also 'new (nothrow)'.
1 
1 '-fconcepts'
1      Enable support for the C++ Extensions for Concepts Technical
1      Specification, ISO 19217 (2015), which allows code like
1 
1           template <class T> concept bool Addable = requires (T t) { t + t; };
1           template <Addable T> T add (T a, T b) { return a + b; }
1 
1 '-fconstexpr-depth=N'
1      Set the maximum nested evaluation depth for C++11 constexpr
1      functions to N.  A limit is needed to detect endless recursion
1      during constant expression evaluation.  The minimum specified by
1      the standard is 512.
1 
1 '-fconstexpr-loop-limit=N'
1      Set the maximum number of iterations for a loop in C++14 constexpr
1      functions to N.  A limit is needed to detect infinite loops during
1      constant expression evaluation.  The default is 262144 (1<<18).
1 
1 '-fdeduce-init-list'
1      Enable deduction of a template type parameter as
1      'std::initializer_list' from a brace-enclosed initializer list,
1      i.e.
1 
1           template <class T> auto forward(T t) -> decltype (realfn (t))
1           {
1             return realfn (t);
1           }
1 
1           void f()
1           {
1             forward({1,2}); // call forward<std::initializer_list<int>>
1           }
1 
1      This deduction was implemented as a possible extension to the
1      originally proposed semantics for the C++11 standard, but was not
1      part of the final standard, so it is disabled by default.  This
1      option is deprecated, and may be removed in a future version of
1      G++.
1 
1 '-ffriend-injection'
1      Inject friend functions into the enclosing namespace, so that they
1      are visible outside the scope of the class in which they are
1      declared.  Friend functions were documented to work this way in the
1      old Annotated C++ Reference Manual.  However, in ISO C++ a friend
1      function that is not declared in an enclosing scope can only be
1      found using argument dependent lookup.  GCC defaults to the
1      standard behavior.
1 
1      This option is deprecated and will be removed.
1 
1 '-fno-elide-constructors'
1      The C++ standard allows an implementation to omit creating a
1      temporary that is only used to initialize another object of the
1      same type.  Specifying this option disables that optimization, and
1      forces G++ to call the copy constructor in all cases.  This option
1      also causes G++ to call trivial member functions which otherwise
1      would be expanded inline.
1 
1      In C++17, the compiler is required to omit these temporaries, but
1      this option still affects trivial member functions.
1 
1 '-fno-enforce-eh-specs'
1      Don't generate code to check for violation of exception
1      specifications at run time.  This option violates the C++ standard,
1      but may be useful for reducing code size in production builds, much
1      like defining 'NDEBUG'.  This does not give user code permission to
1      throw exceptions in violation of the exception specifications; the
1      compiler still optimizes based on the specifications, so throwing
1      an unexpected exception results in undefined behavior at run time.
1 
1 '-fextern-tls-init'
1 '-fno-extern-tls-init'
1      The C++11 and OpenMP standards allow 'thread_local' and
1      'threadprivate' variables to have dynamic (runtime) initialization.
1      To support this, any use of such a variable goes through a wrapper
1      function that performs any necessary initialization.  When the use
1      and definition of the variable are in the same translation unit,
1      this overhead can be optimized away, but when the use is in a
1      different translation unit there is significant overhead even if
1      the variable doesn't actually need dynamic initialization.  If the
1      programmer can be sure that no use of the variable in a
1      non-defining TU needs to trigger dynamic initialization (either
1      because the variable is statically initialized, or a use of the
1      variable in the defining TU will be executed before any uses in
1      another TU), they can avoid this overhead with the
1      '-fno-extern-tls-init' option.
1 
1      On targets that support symbol aliases, the default is
1      '-fextern-tls-init'.  On targets that do not support symbol
1      aliases, the default is '-fno-extern-tls-init'.
1 
1 '-ffor-scope'
1 '-fno-for-scope'
1      If '-ffor-scope' is specified, the scope of variables declared in a
1      for-init-statement is limited to the 'for' loop itself, as
1      specified by the C++ standard.  If '-fno-for-scope' is specified,
1      the scope of variables declared in a for-init-statement extends to
1      the end of the enclosing scope, as was the case in old versions of
1      G++, and other (traditional) implementations of C++.
1 
1      This option is deprecated and the associated non-standard
1      functionality will be removed.
1 
1 '-fno-gnu-keywords'
1      Do not recognize 'typeof' as a keyword, so that code can use this
1      word as an identifier.  You can use the keyword '__typeof__'
1      instead.  This option is implied by the strict ISO C++ dialects:
1      '-ansi', '-std=c++98', '-std=c++11', etc.
1 
1 '-fno-implicit-templates'
1      Never emit code for non-inline templates that are instantiated
1      implicitly (i.e. by use); only emit code for explicit
1      instantiations.  ⇒Template Instantiation, for more
1      information.
1 
1 '-fno-implicit-inline-templates'
1      Don't emit code for implicit instantiations of inline templates,
1      either.  The default is to handle inlines differently so that
1      compiles with and without optimization need the same set of
1      explicit instantiations.
1 
1 '-fno-implement-inlines'
1      To save space, do not emit out-of-line copies of inline functions
1      controlled by '#pragma implementation'.  This causes linker errors
1      if these functions are not inlined everywhere they are called.
1 
1 '-fms-extensions'
1      Disable Wpedantic warnings about constructs used in MFC, such as
1      implicit int and getting a pointer to member function via
1      non-standard syntax.
1 
1 '-fnew-inheriting-ctors'
1      Enable the P0136 adjustment to the semantics of C++11 constructor
1      inheritance.  This is part of C++17 but also considered to be a
1      Defect Report against C++11 and C++14.  This flag is enabled by
1      default unless '-fabi-version=10' or lower is specified.
1 
1 '-fnew-ttp-matching'
1      Enable the P0522 resolution to Core issue 150, template template
1      parameters and default arguments: this allows a template with
1      default template arguments as an argument for a template template
1      parameter with fewer template parameters.  This flag is enabled by
1      default for '-std=c++17'.
1 
1 '-fno-nonansi-builtins'
1      Disable built-in declarations of functions that are not mandated by
1      ANSI/ISO C.  These include 'ffs', 'alloca', '_exit', 'index',
1      'bzero', 'conjf', and other related functions.
1 
1 '-fnothrow-opt'
1      Treat a 'throw()' exception specification as if it were a
1      'noexcept' specification to reduce or eliminate the text size
1      overhead relative to a function with no exception specification.
1      If the function has local variables of types with non-trivial
1      destructors, the exception specification actually makes the
1      function smaller because the EH cleanups for those variables can be
1      optimized away.  The semantic effect is that an exception thrown
1      out of a function with such an exception specification results in a
1      call to 'terminate' rather than 'unexpected'.
1 
1 '-fno-operator-names'
1      Do not treat the operator name keywords 'and', 'bitand', 'bitor',
1      'compl', 'not', 'or' and 'xor' as synonyms as keywords.
1 
1 '-fno-optional-diags'
1      Disable diagnostics that the standard says a compiler does not need
1      to issue.  Currently, the only such diagnostic issued by G++ is the
1      one for a name having multiple meanings within a class.
1 
1 '-fpermissive'
1      Downgrade some diagnostics about nonconformant code from errors to
1      warnings.  Thus, using '-fpermissive' allows some nonconforming
1      code to compile.
1 
1 '-fno-pretty-templates'
1      When an error message refers to a specialization of a function
1      template, the compiler normally prints the signature of the
1      template followed by the template arguments and any typedefs or
1      typenames in the signature (e.g.  'void f(T) [with T = int]' rather
1      than 'void f(int)') so that it's clear which template is involved.
1      When an error message refers to a specialization of a class
1      template, the compiler omits any template arguments that match the
1      default template arguments for that template.  If either of these
1      behaviors make it harder to understand the error message rather
1      than easier, you can use '-fno-pretty-templates' to disable them.
1 
1 '-frepo'
1      Enable automatic template instantiation at link time.  This option
11      also implies '-fno-implicit-templates'.  ⇒Template
      Instantiation, for more information.
1 
1 '-fno-rtti'
1      Disable generation of information about every class with virtual
1      functions for use by the C++ run-time type identification features
1      ('dynamic_cast' and 'typeid').  If you don't use those parts of the
1      language, you can save some space by using this flag.  Note that
1      exception handling uses the same information, but G++ generates it
1      as needed.  The 'dynamic_cast' operator can still be used for casts
1      that do not require run-time type information, i.e. casts to 'void
1      *' or to unambiguous base classes.
1 
1 '-fsized-deallocation'
1      Enable the built-in global declarations
1           void operator delete (void *, std::size_t) noexcept;
1           void operator delete[] (void *, std::size_t) noexcept;
1      as introduced in C++14.  This is useful for user-defined
1      replacement deallocation functions that, for example, use the size
1      of the object to make deallocation faster.  Enabled by default
1      under '-std=c++14' and above.  The flag '-Wsized-deallocation'
1      warns about places that might want to add a definition.
1 
1 '-fstrict-enums'
1      Allow the compiler to optimize using the assumption that a value of
1      enumerated type can only be one of the values of the enumeration
1      (as defined in the C++ standard; basically, a value that can be
1      represented in the minimum number of bits needed to represent all
1      the enumerators).  This assumption may not be valid if the program
1      uses a cast to convert an arbitrary integer value to the enumerated
1      type.
1 
1 '-fstrong-eval-order'
1      Evaluate member access, array subscripting, and shift expressions
1      in left-to-right order, and evaluate assignment in right-to-left
1      order, as adopted for C++17.  Enabled by default with '-std=c++17'.
1      '-fstrong-eval-order=some' enables just the ordering of member
1      access and shift expressions, and is the default without
1      '-std=c++17'.
1 
1 '-ftemplate-backtrace-limit=N'
1      Set the maximum number of template instantiation notes for a single
1      warning or error to N.  The default value is 10.
1 
1 '-ftemplate-depth=N'
1      Set the maximum instantiation depth for template classes to N.  A
1      limit on the template instantiation depth is needed to detect
1      endless recursions during template class instantiation.  ANSI/ISO
1      C++ conforming programs must not rely on a maximum depth greater
1      than 17 (changed to 1024 in C++11).  The default value is 900, as
1      the compiler can run out of stack space before hitting 1024 in some
1      situations.
1 
1 '-fno-threadsafe-statics'
1      Do not emit the extra code to use the routines specified in the C++
1      ABI for thread-safe initialization of local statics.  You can use
1      this option to reduce code size slightly in code that doesn't need
1      to be thread-safe.
1 
1 '-fuse-cxa-atexit'
1      Register destructors for objects with static storage duration with
1      the '__cxa_atexit' function rather than the 'atexit' function.
1      This option is required for fully standards-compliant handling of
1      static destructors, but only works if your C library supports
1      '__cxa_atexit'.
1 
1 '-fno-use-cxa-get-exception-ptr'
1      Don't use the '__cxa_get_exception_ptr' runtime routine.  This
1      causes 'std::uncaught_exception' to be incorrect, but is necessary
1      if the runtime routine is not available.
1 
1 '-fvisibility-inlines-hidden'
1      This switch declares that the user does not attempt to compare
1      pointers to inline functions or methods where the addresses of the
1      two functions are taken in different shared objects.
1 
1      The effect of this is that GCC may, effectively, mark inline
1      methods with '__attribute__ ((visibility ("hidden")))' so that they
1      do not appear in the export table of a DSO and do not require a PLT
1      indirection when used within the DSO.  Enabling this option can
1      have a dramatic effect on load and link times of a DSO as it
1      massively reduces the size of the dynamic export table when the
1      library makes heavy use of templates.
1 
1      The behavior of this switch is not quite the same as marking the
1      methods as hidden directly, because it does not affect static
1      variables local to the function or cause the compiler to deduce
1      that the function is defined in only one shared object.
1 
1      You may mark a method as having a visibility explicitly to negate
1      the effect of the switch for that method.  For example, if you do
1      want to compare pointers to a particular inline method, you might
1      mark it as having default visibility.  Marking the enclosing class
1      with explicit visibility has no effect.
1 
1      Explicitly instantiated inline methods are unaffected by this
1      option as their linkage might otherwise cross a shared library
1      boundary.  ⇒Template Instantiation.
1 
1 '-fvisibility-ms-compat'
1      This flag attempts to use visibility settings to make GCC's C++
1      linkage model compatible with that of Microsoft Visual Studio.
1 
1      The flag makes these changes to GCC's linkage model:
1 
1        1. It sets the default visibility to 'hidden', like
1           '-fvisibility=hidden'.
1 
1        2. Types, but not their members, are not hidden by default.
1 
1        3. The One Definition Rule is relaxed for types without explicit
1           visibility specifications that are defined in more than one
1           shared object: those declarations are permitted if they are
1           permitted when this option is not used.
1 
1      In new code it is better to use '-fvisibility=hidden' and export
1      those classes that are intended to be externally visible.
1      Unfortunately it is possible for code to rely, perhaps
1      accidentally, on the Visual Studio behavior.
1 
1      Among the consequences of these changes are that static data
1      members of the same type with the same name but defined in
1      different shared objects are different, so changing one does not
1      change the other; and that pointers to function members defined in
1      different shared objects may not compare equal.  When this flag is
1      given, it is a violation of the ODR to define types with the same
1      name differently.
1 
1 '-fno-weak'
1      Do not use weak symbol support, even if it is provided by the
1      linker.  By default, G++ uses weak symbols if they are available.
1      This option exists only for testing, and should not be used by
1      end-users; it results in inferior code and has no benefits.  This
1      option may be removed in a future release of G++.
1 
1 '-nostdinc++'
1      Do not search for header files in the standard directories specific
1      to C++, but do still search the other standard directories.  (This
1      option is used when building the C++ library.)
1 
1  In addition, these optimization, warning, and code generation options
1 have meanings only for C++ programs:
1 
1 '-Wabi (C, Objective-C, C++ and Objective-C++ only)'
1      Warn when G++ it generates code that is probably not compatible
1      with the vendor-neutral C++ ABI.  Since G++ now defaults to
1      updating the ABI with each major release, normally '-Wabi' will
1      warn only if there is a check added later in a release series for
1      an ABI issue discovered since the initial release.  '-Wabi' will
1      warn about more things if an older ABI version is selected (with
1      '-fabi-version=N').
1 
1      '-Wabi' can also be used with an explicit version number to warn
1      about compatibility with a particular '-fabi-version' level, e.g.
1      '-Wabi=2' to warn about changes relative to '-fabi-version=2'.
1 
1      If an explicit version number is provided and
1      '-fabi-compat-version' is not specified, the version number from
1      this option is used for compatibility aliases.  If no explicit
1      version number is provided with this option, but
1      '-fabi-compat-version' is specified, that version number is used
1      for ABI warnings.
1 
1      Although an effort has been made to warn about all such cases,
1      there are probably some cases that are not warned about, even
1      though G++ is generating incompatible code.  There may also be
1      cases where warnings are emitted even though the code that is
1      generated is compatible.
1 
1      You should rewrite your code to avoid these warnings if you are
1      concerned about the fact that code generated by G++ may not be
1      binary compatible with code generated by other compilers.
1 
1      Known incompatibilities in '-fabi-version=2' (which was the default
1      from GCC 3.4 to 4.9) include:
1 
1         * A template with a non-type template parameter of reference
1           type was mangled incorrectly:
1                extern int N;
1                template <int &> struct S {};
1                void n (S<N>) {2}
1 
1           This was fixed in '-fabi-version=3'.
1 
1         * SIMD vector types declared using '__attribute ((vector_size))'
1           were mangled in a non-standard way that does not allow for
1           overloading of functions taking vectors of different sizes.
1 
1           The mangling was changed in '-fabi-version=4'.
1 
1         * '__attribute ((const))' and 'noreturn' were mangled as type
1           qualifiers, and 'decltype' of a plain declaration was folded
1           away.
1 
1           These mangling issues were fixed in '-fabi-version=5'.
1 
1         * Scoped enumerators passed as arguments to a variadic function
1           are promoted like unscoped enumerators, causing 'va_arg' to
1           complain.  On most targets this does not actually affect the
1           parameter passing ABI, as there is no way to pass an argument
1           smaller than 'int'.
1 
1           Also, the ABI changed the mangling of template argument packs,
1           'const_cast', 'static_cast', prefix increment/decrement, and a
1           class scope function used as a template argument.
1 
1           These issues were corrected in '-fabi-version=6'.
1 
1         * Lambdas in default argument scope were mangled incorrectly,
1           and the ABI changed the mangling of 'nullptr_t'.
1 
1           These issues were corrected in '-fabi-version=7'.
1 
1         * When mangling a function type with function-cv-qualifiers, the
1           un-qualified function type was incorrectly treated as a
1           substitution candidate.
1 
1           This was fixed in '-fabi-version=8', the default for GCC 5.1.
1 
1         * 'decltype(nullptr)' incorrectly had an alignment of 1, leading
1           to unaligned accesses.  Note that this did not affect the ABI
1           of a function with a 'nullptr_t' parameter, as parameters have
1           a minimum alignment.
1 
1           This was fixed in '-fabi-version=9', the default for GCC 5.2.
1 
1         * Target-specific attributes that affect the identity of a type,
1           such as ia32 calling conventions on a function type (stdcall,
1           regparm, etc.), did not affect the mangled name, leading to
1           name collisions when function pointers were used as template
1           arguments.
1 
1           This was fixed in '-fabi-version=10', the default for GCC 6.1.
1 
1      It also warns about psABI-related changes.  The known psABI changes
1      at this point include:
1 
1         * For SysV/x86-64, unions with 'long double' members are passed
1           in memory as specified in psABI. For example:
1 
1                union U {
1                  long double ld;
1                  int i;
1                };
1 
1           'union U' is always passed in memory.
1 
1 '-Wabi-tag (C++ and Objective-C++ only)'
1      Warn when a type with an ABI tag is used in a context that does not
1      have that ABI tag.  See ⇒C++ Attributes for more information
1      about ABI tags.
1 
1 '-Wctor-dtor-privacy (C++ and Objective-C++ only)'
1      Warn when a class seems unusable because all the constructors or
1      destructors in that class are private, and it has neither friends
1      nor public static member functions.  Also warn if there are no
1      non-private methods, and there's at least one private member
1      function that isn't a constructor or destructor.
1 
1 '-Wdelete-non-virtual-dtor (C++ and Objective-C++ only)'
1      Warn when 'delete' is used to destroy an instance of a class that
1      has virtual functions and non-virtual destructor.  It is unsafe to
1      delete an instance of a derived class through a pointer to a base
1      class if the base class does not have a virtual destructor.  This
1      warning is enabled by '-Wall'.
1 
1 '-Wliteral-suffix (C++ and Objective-C++ only)'
1      Warn when a string or character literal is followed by a ud-suffix
1      which does not begin with an underscore.  As a conforming
1      extension, GCC treats such suffixes as separate preprocessing
1      tokens in order to maintain backwards compatibility with code that
1      uses formatting macros from '<inttypes.h>'.  For example:
1 
1           #define __STDC_FORMAT_MACROS
1           #include <inttypes.h>
1           #include <stdio.h>
1 
1           int main() {
1             int64_t i64 = 123;
1             printf("My int64: %" PRId64"\n", i64);
1           }
1 
1      In this case, 'PRId64' is treated as a separate preprocessing
1      token.
1 
1      Additionally, warn when a user-defined literal operator is declared
1      with a literal suffix identifier that doesn't begin with an
1      underscore.  Literal suffix identifiers that don't begin with an
1      underscore are reserved for future standardization.
1 
1      This warning is enabled by default.
1 
1 '-Wlto-type-mismatch'
1 
1      During the link-time optimization warn about type mismatches in
1      global declarations from different compilation units.  Requires
1      '-flto' to be enabled.  Enabled by default.
1 
1 '-Wno-narrowing (C++ and Objective-C++ only)'
1      For C++11 and later standards, narrowing conversions are diagnosed
1      by default, as required by the standard.  A narrowing conversion
1      from a constant produces an error, and a narrowing conversion from
1      a non-constant produces a warning, but '-Wno-narrowing' suppresses
1      the diagnostic.  Note that this does not affect the meaning of
1      well-formed code; narrowing conversions are still considered
1      ill-formed in SFINAE contexts.
1 
1      With '-Wnarrowing' in C++98, warn when a narrowing conversion
1      prohibited by C++11 occurs within '{ }', e.g.
1 
1           int i = { 2.2 }; // error: narrowing from double to int
1 
1      This flag is included in '-Wall' and '-Wc++11-compat'.
1 
1 '-Wnoexcept (C++ and Objective-C++ only)'
1      Warn when a noexcept-expression evaluates to false because of a
1      call to a function that does not have a non-throwing exception
1      specification (i.e.  'throw()' or 'noexcept') but is known by the
1      compiler to never throw an exception.
1 
1 '-Wnoexcept-type (C++ and Objective-C++ only)'
1      Warn if the C++17 feature making 'noexcept' part of a function type
1      changes the mangled name of a symbol relative to C++14.  Enabled by
1      '-Wabi' and '-Wc++17-compat'.
1 
1      As an example:
1 
1           template <class T> void f(T t) { t(); };
1           void g() noexcept;
1           void h() { f(g); }
1 
1      In C++14, 'f' calls 'f<void(*)()>', but in C++17 it calls
1      'f<void(*)()noexcept>'.
1 
1 '-Wclass-memaccess (C++ and Objective-C++ only)'
1      Warn when the destination of a call to a raw memory function such
1      as 'memset' or 'memcpy' is an object of class type, and when
1      writing into such an object might bypass the class non-trivial or
1      deleted constructor or copy assignment, violate const-correctness
1      or encapsulation, or corrupt virtual table pointers.  Modifying the
1      representation of such objects may violate invariants maintained by
1      member functions of the class.  For example, the call to 'memset'
1      below is undefined because it modifies a non-trivial class object
1      and is, therefore, diagnosed.  The safe way to either initialize or
1      clear the storage of objects of such types is by using the
1      appropriate constructor or assignment operator, if one is
1      available.
1           std::string str = "abc";
1           memset (&str, 0, sizeof str);
1      The '-Wclass-memaccess' option is enabled by '-Wall'.  Explicitly
1      casting the pointer to the class object to 'void *' or to a type
1      that can be safely accessed by the raw memory function suppresses
1      the warning.
1 
1 '-Wnon-virtual-dtor (C++ and Objective-C++ only)'
1      Warn when a class has virtual functions and an accessible
1      non-virtual destructor itself or in an accessible polymorphic base
1      class, in which case it is possible but unsafe to delete an
1      instance of a derived class through a pointer to the class itself
1      or base class.  This warning is automatically enabled if '-Weffc++'
1      is specified.
1 
1 '-Wregister (C++ and Objective-C++ only)'
1      Warn on uses of the 'register' storage class specifier, except when
1      it is part of the GNU ⇒Explicit Register Variables
1      extension.  The use of the 'register' keyword as storage class
1      specifier has been deprecated in C++11 and removed in C++17.
1      Enabled by default with '-std=c++17'.
1 
1 '-Wreorder (C++ and Objective-C++ only)'
1      Warn when the order of member initializers given in the code does
1      not match the order in which they must be executed.  For instance:
1 
1           struct A {
1             int i;
1             int j;
1             A(): j (0), i (1) { }
1           };
1 
1      The compiler rearranges the member initializers for 'i' and 'j' to
1      match the declaration order of the members, emitting a warning to
1      that effect.  This warning is enabled by '-Wall'.
1 
1 '-fext-numeric-literals (C++ and Objective-C++ only)'
1      Accept imaginary, fixed-point, or machine-defined literal number
1      suffixes as GNU extensions.  When this option is turned off these
1      suffixes are treated as C++11 user-defined literal numeric
1      suffixes.  This is on by default for all pre-C++11 dialects and all
1      GNU dialects: '-std=c++98', '-std=gnu++98', '-std=gnu++11',
1      '-std=gnu++14'.  This option is off by default for ISO C++11
1      onwards ('-std=c++11', ...).
1 
1  The following '-W...' options are not affected by '-Wall'.
1 
1 '-Weffc++ (C++ and Objective-C++ only)'
1      Warn about violations of the following style guidelines from Scott
1      Meyers' 'Effective C++' series of books:
1 
1         * Define a copy constructor and an assignment operator for
1           classes with dynamically-allocated memory.
1 
1         * Prefer initialization to assignment in constructors.
1 
1         * Have 'operator=' return a reference to '*this'.
1 
1         * Don't try to return a reference when you must return an
1           object.
1 
1         * Distinguish between prefix and postfix forms of increment and
1           decrement operators.
1 
1         * Never overload '&&', '||', or ','.
1 
1      This option also enables '-Wnon-virtual-dtor', which is also one of
1      the effective C++ recommendations.  However, the check is extended
1      to warn about the lack of virtual destructor in accessible
1      non-polymorphic bases classes too.
1 
1      When selecting this option, be aware that the standard library
1      headers do not obey all of these guidelines; use 'grep -v' to
1      filter out those warnings.
1 
1 '-Wstrict-null-sentinel (C++ and Objective-C++ only)'
1      Warn about the use of an uncasted 'NULL' as sentinel.  When
1      compiling only with GCC this is a valid sentinel, as 'NULL' is
1      defined to '__null'.  Although it is a null pointer constant rather
1      than a null pointer, it is guaranteed to be of the same size as a
1      pointer.  But this use is not portable across different compilers.
1 
1 '-Wno-non-template-friend (C++ and Objective-C++ only)'
1      Disable warnings when non-template friend functions are declared
1      within a template.  In very old versions of GCC that predate
1      implementation of the ISO standard, declarations such as 'friend
1      int foo(int)', where the name of the friend is an unqualified-id,
1      could be interpreted as a particular specialization of a template
1      function; the warning exists to diagnose compatibility problems,
1      and is enabled by default.
1 
1 '-Wold-style-cast (C++ and Objective-C++ only)'
1      Warn if an old-style (C-style) cast to a non-void type is used
1      within a C++ program.  The new-style casts ('dynamic_cast',
1      'static_cast', 'reinterpret_cast', and 'const_cast') are less
1      vulnerable to unintended effects and much easier to search for.
1 
1 '-Woverloaded-virtual (C++ and Objective-C++ only)'
1      Warn when a function declaration hides virtual functions from a
1      base class.  For example, in:
1 
1           struct A {
1             virtual void f();
1           };
1 
1           struct B: public A {
1             void f(int);
1           };
1 
1      the 'A' class version of 'f' is hidden in 'B', and code like:
1 
1           B* b;
1           b->f();
1 
1      fails to compile.
1 
1 '-Wno-pmf-conversions (C++ and Objective-C++ only)'
1      Disable the diagnostic for converting a bound pointer to member
1      function to a plain pointer.
1 
1 '-Wsign-promo (C++ and Objective-C++ only)'
1      Warn when overload resolution chooses a promotion from unsigned or
1      enumerated type to a signed type, over a conversion to an unsigned
1      type of the same size.  Previous versions of G++ tried to preserve
1      unsignedness, but the standard mandates the current behavior.
1 
1 '-Wtemplates (C++ and Objective-C++ only)'
1      Warn when a primary template declaration is encountered.  Some
1      coding rules disallow templates, and this may be used to enforce
1      that rule.  The warning is inactive inside a system header file,
1      such as the STL, so one can still use the STL. One may also
1      instantiate or specialize templates.
1 
1 '-Wmultiple-inheritance (C++ and Objective-C++ only)'
1      Warn when a class is defined with multiple direct base classes.
1      Some coding rules disallow multiple inheritance, and this may be
1      used to enforce that rule.  The warning is inactive inside a system
1      header file, such as the STL, so one can still use the STL. One may
1      also define classes that indirectly use multiple inheritance.
1 
1 '-Wvirtual-inheritance'
1      Warn when a class is defined with a virtual direct base class.
1      Some coding rules disallow multiple inheritance, and this may be
1      used to enforce that rule.  The warning is inactive inside a system
1      header file, such as the STL, so one can still use the STL. One may
1      also define classes that indirectly use virtual inheritance.
1 
1 '-Wnamespaces'
1      Warn when a namespace definition is opened.  Some coding rules
1      disallow namespaces, and this may be used to enforce that rule.
1      The warning is inactive inside a system header file, such as the
1      STL, so one can still use the STL. One may also use using
1      directives and qualified names.
1 
1 '-Wno-terminate (C++ and Objective-C++ only)'
1      Disable the warning about a throw-expression that will immediately
1      result in a call to 'terminate'.
1