GCC是每個從事Linux,以及嵌入式開發等必備的編譯器,由于幫助手冊較多,這裡使用了分頁的形式進行分享,如下為Ubuntu Server 22.04作業系統平台和GCC編譯器的基本資訊。
GCC幫助手冊的第7小節,第1448~1688行。
1448 -fsized-deallocation
1449 Enable the built-in global declarations
1450 void operator delete (void *, std::size_t) noexcept;
1451 void operator delete[] (void *, std::size_t) noexcept;
1452 as introduced in C++14. This is useful for user-defined replacement deallocation functions that, for
1453 example, use the size of the object to make deallocation faster. Enabled by default under -std=c++14 and
1454 above. The flag -Wsized-deallocation warns about places that might want to add a definition.
1455 -fstrict-enums
1456 Allow the compiler to optimize using the assumption that a value of enumerated type can only be one of the
1457 values of the enumeration (as defined in the C++ standard; basically, a value that can be represented in
1458 the minimum number of bits needed to represent all the enumerators). This assumption may not be valid if
1459 the program uses a cast to convert an arbitrary integer value to the enumerated type.
1460 -fstrong-eval-order
1461 Evaluate member access, array subscripting, and shift expressions in left-to-right order, and evaluate
1462 assignment in right-to-left order, as adopted for C++17. Enabled by default with -std=c++17.
1463 -fstrong-eval-order=some enables just the ordering of member access and shift expressions, and is the
1464 default without -std=c++17.
1465 -ftemplate-backtrace-limit=n
1466 Set the maximum number of template instantiation notes for a single warning or error to n. The default
1467 value is 10.
1468 -ftemplate-depth=n
1469 Set the maximum instantiation depth for template classes to n. A limit on the template instantiation depth
1470 is needed to detect endless recursions during template class instantiation. ANSI/ISO C++ conforming
1471 programs must not rely on a maximum depth greater than 17 (changed to 1024 in C++11). The default value is
1472 900, as the compiler can run out of stack space before hitting 1024 in some situations.
1473 -fno-threadsafe-statics
1474 Do not emit the extra code to use the routines specified in the C++ ABI for thread-safe initialization of
1475 local statics. You can use this option to reduce code size slightly in code that doesn't need to be
1476 thread-safe.
1477 -fuse-cxa-atexit
1478 Register destructors for objects with static storage duration with the "__cxa_atexit" function rather than
1479 the "atexit" function. This option is required for fully standards-compliant handling of static
1480 destructors, but only works if your C library supports "__cxa_atexit".
1481 -fno-use-cxa-get-exception-ptr
1482 Don't use the "__cxa_get_exception_ptr" runtime routine. This causes "std::uncaught_exception" to be
1483 incorrect, but is necessary if the runtime routine is not available.
1484 -fvisibility-inlines-hidden
1485 This switch declares that the user does not attempt to compare pointers to inline functions or methods
1486 where the addresses of the two functions are taken in different shared objects.
1487 The effect of this is that GCC may, effectively, mark inline methods with "__attribute__ ((visibility
1488 ("hidden")))" so that they do not appear in the export table of a DSO and do not require a PLT indirection
1489 when used within the DSO. Enabling this option can have a dramatic effect on load and link times of a DSO
1490 as it massively reduces the size of the dynamic export table when the library makes heavy use of templates.
1491 The behavior of this switch is not quite the same as marking the methods as hidden directly, because it
1492 does not affect static variables local to the function or cause the compiler to deduce that the function is
1493 defined in only one shared object.
1494 You may mark a method as having a visibility explicitly to negate the effect of the switch for that method.
1495 For example, if you do want to compare pointers to a particular inline method, you might mark it as having
1496 default visibility. Marking the enclosing class with explicit visibility has no effect.
1497 Explicitly instantiated inline methods are unaffected by this option as their linkage might otherwise cross
1498 a shared library boundary.
1499 -fvisibility-ms-compat
1500 This flag attempts to use visibility settings to make GCC's C++ linkage model compatible with that of
1501 Microsoft Visual Studio.
1502 The flag makes these changes to GCC's linkage model:
1503 1. It sets the default visibility to "hidden", like -fvisibility=hidden.
1504 2. Types, but not their members, are not hidden by default.
1505 3. The One Definition Rule is relaxed for types without explicit visibility specifications that are
1506 defined in more than one shared object: those declarations are permitted if they are permitted when
1507 this option is not used.
1508 In new code it is better to use -fvisibility=hidden and export those classes that are intended to be
1509 externally visible. Unfortunately it is possible for code to rely, perhaps accidentally, on the Visual
1510 Studio behavior.
1511 Among the consequences of these changes are that static data members of the same type with the same name
1512 but defined in different shared objects are different, so changing one does not change the other; and that
1513 pointers to function members defined in different shared objects may not compare equal. When this flag is
1514 given, it is a violation of the ODR to define types with the same name differently.
1515 -fno-weak
1516 Do not use weak symbol support, even if it is provided by the linker. By default, G++ uses weak symbols if
1517 they are available. This option exists only for testing, and should not be used by end-users; it results
1518 in inferior code and has no benefits. This option may be removed in a future release of G++.
1519 -fext-numeric-literals (C++ and Objective-C++ only)
1520 Accept imaginary, fixed-point, or machine-defined literal number suffixes as GNU extensions. When this
1521 option is turned off these suffixes are treated as C++11 user-defined literal numeric suffixes. This is on
1522 by default for all pre-C++11 dialects and all GNU dialects: -std=c++98, -std=gnu++98, -std=gnu++11,
1523 -std=gnu++14. This option is off by default for ISO C++11 onwards (-std=c++11, ...).
1524 -nostdinc++
1525 Do not search for header files in the standard directories specific to C++, but do still search the other
1526 standard directories. (This option is used when building the C++ library.)
1527 -flang-info-include-translate
1528 -flang-info-include-translate-not
1529 -flang-info-include-translate=header
1530 Inform of include translation events. The first will note accepted include translations, the second will
1531 note declined include translations. The header form will inform of include translations relating to that
1532 specific header. If header is of the form "user" or "<system>" it will be resolved to a specific user or
1533 system header using the include path.
1534 -flang-info-module-cmi
1535 -flang-info-module-cmi=module
1536 Inform of Compiled Module Interface pathnames. The first will note all read CMI pathnames. The module
1537 form will not reading a specific module's CMI. module may be a named module or a header-unit (the latter
1538 indicated by either being a pathname containing directory separators or enclosed in "<>" or "").
1539 -stdlib=libstdc++,libc++
1540 When G++ is configured to support this option, it allows specification of alternate C++ runtime libraries.
1541 Two options are available: libstdc++ (the default, native C++ runtime for G++) and libc++ which is the C++
1542 runtime installed on some operating systems (e.g. Darwin versions from Darwin11 onwards). The option
1543 switches G++ to use the headers from the specified library and to emit "-lstdc++" or "-lc++" respectively,
1544 when a C++ runtime is required for linking.
1545 In addition, these warning options have meanings only for C++ programs:
1546 -Wabi-tag (C++ and Objective-C++ only)
1547 Warn when a type with an ABI tag is used in a context that does not have that ABI tag. See C++ Attributes
1548 for more information about ABI tags.
1549 -Wcomma-subscript (C++ and Objective-C++ only)
1550 Warn about uses of a comma expression within a subscripting expression. This usage was deprecated in
1551 C++20. However, a comma expression wrapped in "( )" is not deprecated. Example:
1552 void f(int *a, int b, int c) {
1553 a[b,c]; // deprecated
1554 a[(b,c)]; // OK
1555 }
1556 Enabled by default with -std=c++20.
1557 -Wctad-maybe-unsupported (C++ and Objective-C++ only)
1558 Warn when performing class template argument deduction (CTAD) on a type with no explicitly written
1559 deduction guides. This warning will point out cases where CTAD succeeded only because the compiler
1560 synthesized the implicit deduction guides, which might not be what the programmer intended. Certain style
1561 guides allow CTAD only on types that specifically "opt-in"; i.e., on types that are designed to support
1562 CTAD. This warning can be suppressed with the following pattern:
1563 struct allow_ctad_t; // any name works
1564 template <typename T> struct S {
1565 S(T) { }
1566 };
1567 S(allow_ctad_t) -> S<void>; // guide with incomplete parameter type will never be considered
1568 -Wctor-dtor-privacy (C++ and Objective-C++ only)
1569 Warn when a class seems unusable because all the constructors or destructors in that class are private, and
1570 it has neither friends nor public static member functions. Also warn if there are no non-private methods,
1571 and there's at least one private member function that isn't a constructor or destructor.
1572 -Wdelete-non-virtual-dtor (C++ and Objective-C++ only)
1573 Warn when "delete" is used to destroy an instance of a class that has virtual functions and non-virtual
1574 destructor. It is unsafe to delete an instance of a derived class through a pointer to a base class if the
1575 base class does not have a virtual destructor. This warning is enabled by -Wall.
1576 -Wdeprecated-copy (C++ and Objective-C++ only)
1577 Warn that the implicit declaration of a copy constructor or copy assignment operator is deprecated if the
1578 class has a user-provided copy constructor or copy assignment operator, in C++11 and up. This warning is
1579 enabled by -Wextra. With -Wdeprecated-copy-dtor, also deprecate if the class has a user-provided
1580 destructor.
1581 -Wno-deprecated-enum-enum-conversion (C++ and Objective-C++ only)
1582 Disable the warning about the case when the usual arithmetic conversions are applied on operands where one
1583 is of enumeration type and the other is of a different enumeration type. This conversion was deprecated in
1584 C++20. For example:
1585 enum E1 { e };
1586 enum E2 { f };
1587 int k = f - e;
1588 -Wdeprecated-enum-enum-conversion is enabled by default with -std=c++20. In pre-C++20 dialects, this
1589 warning can be enabled by -Wenum-conversion.
1590 -Wno-deprecated-enum-float-conversion (C++ and Objective-C++ only)
1591 Disable the warning about the case when the usual arithmetic conversions are applied on operands where one
1592 is of enumeration type and the other is of a floating-point type. This conversion was deprecated in C++20.
1593 For example:
1594 enum E1 { e };
1595 enum E2 { f };
1596 bool b = e <= 3.7;
1597 -Wdeprecated-enum-float-conversion is enabled by default with -std=c++20. In pre-C++20 dialects, this
1598 warning can be enabled by -Wenum-conversion.
1599 -Wno-init-list-lifetime (C++ and Objective-C++ only)
1600 Do not warn about uses of "std::initializer_list" that are likely to result in dangling pointers. Since
1601 the underlying array for an "initializer_list" is handled like a normal C++ temporary object, it is easy to
1602 inadvertently keep a pointer to the array past the end of the array's lifetime. For example:
1603 * If a function returns a temporary "initializer_list", or a local "initializer_list" variable, the
1604 array's lifetime ends at the end of the return statement, so the value returned has a dangling pointer.
1605 * If a new-expression creates an "initializer_list", the array only lives until the end of the enclosing
1606 full-expression, so the "initializer_list" in the heap has a dangling pointer.
1607 * When an "initializer_list" variable is assigned from a brace-enclosed initializer list, the temporary
1608 array created for the right side of the assignment only lives until the end of the full-expression, so
1609 at the next statement the "initializer_list" variable has a dangling pointer.
1610 // li's initial underlying array lives as long as li
1611 std::initializer_list<int> li = { 1,2,3 };
1612 // assignment changes li to point to a temporary array
1613 li = { 4, 5 };
1614 // now the temporary is gone and li has a dangling pointer
1615 int i = li.begin()[0] // undefined behavior
1616 * When a list constructor stores the "begin" pointer from the "initializer_list" argument, this doesn't
1617 extend the lifetime of the array, so if a class variable is constructed from a temporary
1618 "initializer_list", the pointer is left dangling by the end of the variable declaration statement.
1619 -Winvalid-imported-macros
1620 Verify all imported macro definitions are valid at the end of compilation. This is not enabled by default,
1621 as it requires additional processing to determine. It may be useful when preparing sets of header-units to
1622 ensure consistent macros.
1623 -Wno-literal-suffix (C++ and Objective-C++ only)
1624 Do not warn when a string or character literal is followed by a ud-suffix which does not begin with an
1625 underscore. As a conforming extension, GCC treats such suffixes as separate preprocessing tokens in order
1626 to maintain backwards compatibility with code that uses formatting macros from "<inttypes.h>". For
1627 example:
1628 #define __STDC_FORMAT_MACROS
1629 #include <inttypes.h>
1630 #include <stdio.h>
1631 int main() {
1632 int64_t i64 = 123;
1633 printf("My int64: %" PRId64"\n", i64);
1634 }
1635 In this case, "PRId64" is treated as a separate preprocessing token.
1636 This option also controls warnings when a user-defined literal operator is declared with a literal suffix
1637 identifier that doesn't begin with an underscore. Literal suffix identifiers that don't begin with an
1638 underscore are reserved for future standardization.
1639 These warnings are enabled by default.
1640 -Wno-narrowing (C++ and Objective-C++ only)
1641 For C++11 and later standards, narrowing conversions are diagnosed by default, as required by the standard.
1642 A narrowing conversion from a constant produces an error, and a narrowing conversion from a non-constant
1643 produces a warning, but -Wno-narrowing suppresses the diagnostic. Note that this does not affect the
1644 meaning of well-formed code; narrowing conversions are still considered ill-formed in SFINAE contexts.
1645 With -Wnarrowing in C++98, warn when a narrowing conversion prohibited by C++11 occurs within { }, e.g.
1646 int i = { 2.2 }; // error: narrowing from double to int
1647 This flag is included in -Wall and -Wc++11-compat.
1648 -Wnoexcept (C++ and Objective-C++ only)
1649 Warn when a noexcept-expression evaluates to false because of a call to a function that does not have a
1650 non-throwing exception specification (i.e. "throw()" or "noexcept") but is known by the compiler to never
1651 throw an exception.
1652 -Wnoexcept-type (C++ and Objective-C++ only)
1653 Warn if the C++17 feature making "noexcept" part of a function type changes the mangled name of a symbol
1654 relative to C++14. Enabled by -Wabi and -Wc++17-compat.
1655 As an example:
1656 template <class T> void f(T t) { t(); };
1657 void g() noexcept;
1658 void h() { f(g); }
1659 In C++14, "f" calls "f<void(*)()>", but in C++17 it calls "f<void(*)()noexcept>".
1660 -Wclass-memaccess (C++ and Objective-C++ only)
1661 Warn when the destination of a call to a raw memory function such as "memset" or "memcpy" is an object of
1662 class type, and when writing into such an object might bypass the class non-trivial or deleted constructor
1663 or copy assignment, violate const-correctness or encapsulation, or corrupt virtual table pointers.
1664 Modifying the representation of such objects may violate invariants maintained by member functions of the
1665 class. For example, the call to "memset" below is undefined because it modifies a non-trivial class object
1666 and is, therefore, diagnosed. The safe way to either initialize or clear the storage of objects of such
1667 types is by using the appropriate constructor or assignment operator, if one is available.
1668 std::string str = "abc";
1669 memset (&str, 0, sizeof str);
1670 The -Wclass-memaccess option is enabled by -Wall. Explicitly casting the pointer to the class object to
1671 "void *" or to a type that can be safely accessed by the raw memory function suppresses the warning.
1672 -Wnon-virtual-dtor (C++ and Objective-C++ only)
1673 Warn when a class has virtual functions and an accessible non-virtual destructor itself or in an accessible
1674 polymorphic base class, in which case it is possible but unsafe to delete an instance of a derived class
1675 through a pointer to the class itself or base class. This warning is automatically enabled if -Weffc++ is
1676 specified.
1677 -Wregister (C++ and Objective-C++ only)
1678 Warn on uses of the "register" storage class specifier, except when it is part of the GNU Explicit Register
1679 Variables extension. The use of the "register" keyword as storage class specifier has been deprecated in
1680 C++11 and removed in C++17. Enabled by default with -std=c++17.
1681 -Wreorder (C++ and Objective-C++ only)
1682 Warn when the order of member initializers given in the code does not match the order in which they must be
1683 executed. For instance:
1684 struct A {
1685 int i;
1686 int j;
1687 A(): j (0), i (1) { }
1688 };